#包含“stdio.h”
# include & ltstring.h & gt
結構研究{
char nm[21],id[12];
int s[5];
};
int main(int argc,char *argv[]){
結構STU stu
char ts[21];
FILE * fp
if(fp=fopen("stu.dat "," r "){
printf("請輸入姓名或ID...\ n ");
scanf("%20s ",ts);
printf(" \ n查找結果是:\ n ");
while(fscanf(fp," %s%s%d%d%d%d%d ",stu.nm,stu.id,stu.s,stu.s+1,stu.s+2,stu.s+3,stu.s+4)!=EOF)
if(strcmp(ts,stu.nm)==0 || strcmp(ts,stu.id)==0){
printf(" % s \ t % s % 4d % 4d % 4d % 4d \ n ",stu.nm,stu.id,stu.s[0],stu.s[1],stu.s[2],stu.s[3],stu . s[4]);
fclose(FP);
返回0;
}
printf("未找到...\ n ");
fclose(FP);
}
其他
printf("打開文件失敗,退出...\ n ");
返回0;
}