c 语言 错在哪?为什么不能匹配姓名?
输入名字后 不能seach到资料txt里有这个人的资料
printf不出 但是程序能运行
//search the data
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXNAME 50
#define MAXSTAFF 100
struct DATA{
char name[MAXNAME];
int age;
int salary;
}staff[MAXSTAFF];
int main()
{
char staff_name[50];
int i;
char ch,y;
FILE*filename;
filename = fopen("staff.txt","r+");
if(filename==NULL)//CHECK FILE EXISTANCE in hd
{
printf("\nFailed to open");
exit(1);
}
printf("The staff record you want to search?");
printf("Enter the staff name");
fflush(stdin);
gets(staff_name);
for(i=0;i<MAXSTAFF;i++)
if(strcmp(staff_name,staff[i].name)==NULL)
{
printf("%s%d%d",staff[i].name,staff[i].age,staff[i].salary);
}
else
continue;
fclose(filename);
return 0;
}