Problems with search in fail
Hi all
I have some problems with searching in fail.
I have mass of structs and I need to find user's telephone number by his name.
Please tell me what I do wrong!!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
FILE *fp;
fp= fopen("info.dat","rb");
if (fp == NULL)
printf("Fail not open");
else
{
char searchname[10];
int fsize;
bool r;
fseek(fp,0,SEEK_END);
fsize = ftell(fp);
I int n = fsize / sizeof(infouser);
infouser* infouser_mas = new infouser[n];
fseek(fp,0,SEEK_SET);
fread(infouser_mas,sizeof(infouser),n,fp);
printf("Enter user name: ");
cin.getline(searchname, 10);
cin.get();
for (int i = 0; i<n ; i++)
{
if ( strcmp (infouser_mas[i].name, searchname)==0)
{
cout << "\nUser name : " << infouser_mas[i].name <<" -> " << infouser_mas[i].telefonnumber << endl;
r=true;
}
}
if ( r == false)
{
cout << "No user found!";
}
fclose(fp);
}
|
Topic archived. No new replies allowed.