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 39 40
| #include<stdio.h> #include<string.h> extern void solve(); int main(void) { FILE *f=fopen("a.txt","w"); fprintf(f, "%s\n", "11405200101 zhangsan 70 80 90 2140 80"); fprintf(f, "%s\n", "11405200102 lisi 80 60 70 210 70"); fprintf(f, "%s\n", "11405200103 lisasdsi 80 10 70 220 70"); fprintf(f, "%s\n", "11405200104 liassi 80 60 70 240 70"); fprintf(f, "%s\n", "11405200105 lzissssi 80 30 76 210 70"); fprintf(f, "%s\n", "11405200106 lisgsi 80 50 70 210 70"); fprintf(f, "%s\n", "11405200107 lizssi 80 67 70 280 76"); fprintf(f, "%s\n", "11405200108 lisqsi 80 60 70 210 70"); fprintf(f, "%s", "11405200109 lisdssi 80 67 70 210 70"); fclose(f); char s[100]; scanf("%s",&s); solve(s); return 0; }
void solve(char s[]) { FILE *fq = fopen("a.txt", "r"); int n; char line[20], a[100]; for (n = 0; n < 9; n++) { fgets(line, 12, fq); fgets(a, 100, fq); if (strcmp(s, line) == 0) { printf("%s %s", line, a); fclose(fq); break; } if (n == 8) { printf("Not Found!"); } } }
|