Where can there be a mistake?
The problem is in the withdrawal of the phone by the name of the subscriber. Namely, the comparison of the user's request with ms [i] .fio does not work.
#include<stdio.h> #include<string.h> #include<conio.h> //Π΄Π»Ρ getch() #include<clocale> //Π΄Π»Ρ Π»ΠΎΠΊΠ°Π»ΠΈΠ·Π°ΡΠΈΠΈ int main() { setlocale(LC_CTYPE, "Russian"); char familiya[15]; struct ABONENT { char fio[21]; int tel; int god; }; FILE *file; struct ABONENT ms[300]; int i = 0; //ΠΎΡΠ΅ΡΠ΅Π΄Π½ΠΎΠΉ ΡΠ»Π΅ΠΌΠ΅Π½Ρ ΠΌΠ°ΡΡΠΈΠ²Π° int j; // Π½ΠΎΠΌΠ΅Ρ ΡΠΈΠΌΠ²ΠΎΠ»Π° ΡΠ°ΠΌΠΈΠ»ΠΈΠΈΠΈ if ((file = fopen("Π°Π±ΠΎΠ½Π΅Π½ΡΡ.txt", "r")) == NULL) puts("Π ΡΠ΅ΠΊΡΡΠ΅ΠΌ ΠΊΠ°ΡΠ°Π»ΠΎΠ³Π΅ ΡΠ°ΠΉΠ» Π½Π΅ Π½Π°ΠΉΠ΄Π΅Π½"); // ΡΡΠ΅Π½ΠΈΠ΅ ΠΈΠ½ΡΠΎΡΠΌΠ°ΡΠΈΠΈ ΠΈΠ· ΡΠ°ΠΉΠ»Π° Π² ΠΌΠ°ΡΡΠΈΠ² ms* while (!feof(file)) { fgets(ms[i].fio, 15, file); fscanf(file, "%d %d", &ms[i].tel, &ms[i].god); i++; } // ΠΏΠΎΠΈΡΠΊ ΠΏΠΎ ΡΠ°ΠΌΠΈΠ»ΠΈΠΈΠΈ puts("ΠΠΎΠΆΠ°Π»ΡΠΉΡΡΠ°, Π²Π²Π΅Π΄ΠΈΡΠ΅ ΡΠ°ΠΌΠΈΠ»ΠΈΡ Π°Π±ΠΎΠ½Π΅Π½ΡΠ°"); int k = i; // Π½ΠΎΠΌΠ΅Ρ ΠΏΠΎΡΠ»Π΅Π΄Π½Π΅Π³ΠΎ ΡΠ»Π΅ΠΌΠ΅Π½ΡΠ° ΠΌΠ°ΡΡΠΈΠ²Π° ms for (i = 0; i <= k; i++) { for (j = 0; j <= 21; j++) { if (ms[i].fio[j] == ' ') ms[i].fio[j] = '\0'; } } gets(familiya); bool net = 0; for (i = 0; i <= k; i++) { if (ms[i].fio == familiya) printf("%d", ms[i].tel); net = 1; } if (net == 1) puts("Π Π±Π°Π·Π΅ Π½Π΅Ρ Π°Π±ΠΎΠ½Π΅Π½ΡΠ° Ρ ΡΠ°ΠΊΠΎΠΉ ΡΠ°ΠΌΠΈΠ»ΠΈΠ΅ΠΉ"); getch(); }
When debugging, it seems that familiya and str [i] .fio match:
But the result: