程序代码:
#include<stdio.h> void main () { FILE *infile, *outfile; int x, on, off; char credit[30], name[30]; printf("\nMy SID is 059353128"); infile=fopen("tobill.txt", "r"); outfile=fopen("record.txt", "w"); for (x=1; x<28; x++) { fscanf(infile, "%[^:]:%[^:]:%d:%d", credit, name, &on, &off); getc(infile); } fprintf(outfile, "Record %d is : %s %s %d %d\n", x, credit, name, on, off); fclose(infile); fclose(outfile); }
把你上面的代码改了一下,亲测可以了。
不要问我下课干什么,我陪瓜哥上厕所。