#include <stdio.h>
#include <string.h>
main()
{
//测试文件
FILE *fp = fopen("test.txt", "w+");
fprintf(fp, "%s %s %s %s\n", "987","CA","xiamen","beijing");
fprintf(fp, "%s %s %s %s\n", "876","CZ","wuhan","hangzhou");
fseek(fp, 0, SEEK_SET);
//用户输入987和xiamen后,查找符合要求的记录
char nb[10],cm[10],nm[10],ct[10];
while (fscanf(fp, "%s%s%s%s", nb,cm,nm,ct) == 4)
if (strcmp(nb,"987")==0 && strcmp(nm,"xiamen")==0)
printf("%s %s %s %s\n", nb,cm,nm,ct);
fclose(fp);
}