When compiling, the program does not produce errors, but during startup it shows incorrect results:
It seems to me that she does not read the salary of workers, but I do not know why.
The problem itself:
Given a file containing information about employees. The file entry structure:
- Personnel Number.
- Name and initials of the employee.
- position.
- salary.
Write a program that: 1. displays a list of employees for a given position; 2. display a list of employees with a minimum salary;
The code itself:
#include<stdio.h> #include<string.h> #include<conio.h> #include<clocale> #include<Windows.h> struct SOTRUDNIK { char fio[21]; char dol[21]; int tn; int zarplata; }; void Dol(int k, SOTRUDNIK * str); void Zap(int k, SOTRUDNIK * str); int main() { int zap; setlocale(LC_CTYPE, "Russian"); int i; FILE *f; struct SOTRUDNIK str[300]; if ((f = fopen("ΡΠΎΡΡΡΠ΄Π½ΠΈΠΊΠΈ.txt", "r")) == NULL) puts("Π€Π°ΠΉΠ» Π½Π΅ Π½Π°ΠΉΠ΄Π΅Π½."); for (i = 0; !feof(f); i++) { fgets(str[i].fio, 20, f); fgets(str[i].dol, 20, f); fscanf(f, "%d %d", &str[i].tn, &str[i].zarplata); } int k = i; char c; bool proof = true; for (int i = 0; i <= k; i++) { for (int j = 0; j <= 21; j++) { if (str[i].dol[j] == ' ') str[i].dol[j] = '\0'; } } do { if (proof) { puts("___________________________________________"); puts("ΠΡΠ±Π΅ΡΠΈΡΠ΅ Π΄Π΅ΠΉΡΡΠ²ΠΈΠ΅:"); puts("1-Π²ΡΠ²ΠΎΠ΄ ΡΠΎΡΡΡΠ΄Π½ΠΈΠΊΠΎΠ² ΠΏΠΎ Π·Π°Π΄Π°Π½Π½ΠΎΠΉ Π΄ΠΎΠ»ΠΆΠ½ΠΎΡΡΠΈ"); puts("2-Π²ΡΠ²ΠΎΠ΄ ΡΠΎΡΡΡΠ΄Π½ΠΈΠΊΠΎΠ² Ρ ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡΠ½ΠΎΠΉ Π·Π°ΡΠΏΠ»Π°ΡΠΎΠΉ"); puts("3-Π΄Π»Ρ Π²ΡΡ
ΠΎΠ΄Π°"); puts("___________________________________________"); } c = getchar(); proof = true; switch (c) { case '1': Dol(k, str); break; case '2': Zap(k, str); break; case '3': return 0; fclose(f); break; default: proof = false; break; } } while (c = '!3'); } void Dol(int k, SOTRUDNIK * str) { char dolC[21]; bool naiden = 0; puts("ΠΠ²Π΅Π΄ΠΈΡΠ΅ Π΄ΠΎΠ»ΠΆΠ½ΠΎΡΡΡ:"); scanf("%s", dolC); for (int i = 0; i <= k; i++) if (strcmp(str[i].dol, dolC) == 0) { printf("%d %s %s", str[i].tn, str[i].fio, str[i].zarplata); naiden = 1; } if (naiden == 0) printf ("Π Π±Π°Π·Π΅ Π½Π΅Ρ ΡΠ°Π±ΠΎΡΠ½ΠΈΠΊΠ° Ρ ΡΠ°ΠΊΠΎΠΉ Π΄ΠΎΠ»ΠΆΠ½ΠΎΡΡΡΡ"); puts("ΠΠ»Ρ Π²ΠΎΠ·Π²ΡΠ°ΡΠ° Π² ΠΌΠ΅Π½Ρ Π½Π°ΠΆΠΌΠΈΡΠ΅ Π»ΡΠ±ΡΡ ΠΊΠ»Π°Π²ΠΈΡΡ"); getchar(); getchar(); system("cls"); } void Zap(int k, SOTRUDNIK * str) { int minzap = 100000; puts("Π‘ΠΎΡΡΡΠ΄Π½ΠΈΠΊΠΈ Ρ ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡΠ½ΠΎΠΉ Π·Π°ΡΠΏΠ»Π°ΡΠΎΠΉ:"); puts("\n β Π€ΠΠ Π·Π°ΡΠΏΠ»Π°ΡΠ°"); puts("___________________________________________"); for (int i = 0; i <= k; i++) { if (minzap > str[i].zarplata) minzap = str[i].zarplata; } for (int i = 0; i <= k; i++) if (minzap == str[i].zarplata) printf("\n %d %s %d", str[i].tn, str[i].fio, str[i].zarplata); puts("___________________________________________"); puts("ΠΠ»Ρ Π²ΠΎΠ·Π²ΡΠ°ΡΠ° Π² ΠΌΠ΅Π½Ρ Π½Π°ΠΆΠΌΠΈΡΠ΅ Π»ΡΠ±ΡΡ ΠΊΠ»Π°Π²ΠΈΡΡ"); getchar(); getchar(); system("cls"); }
The data from the text file employees.txt:
1 ΠΠ°ΡΠΈΠ»ΡΠ΅Π² ΡΠ΅ΠΊΡΠ΅ΡΠ°ΡΡ 5000 2 ΠΡΠ±ΠΊΠΎΠ² ΠΌΠ΅Π½Π΅Π΄ΠΆΠ΅Ρ 6000 3 ΠΠΆΠ΅ΠΊΡΠΎΠ½ ΠΌΠ΅Π½Π΅Π΄ΠΆΠ΅Ρ 4000
Help, please, this problem has been hindering me for several days, at first I didnβt want to bother with trivia.
while(c='!3');
? - alexlz