Hello, 大家好,我是爱吃香蕉的猴子,记录一下addaword.c程序
#include#include #include #define MAX 40 int main(void) { FILE *fp; char words[MAX]; if((fp = fopen("words", "a+")) == NULL) { fprintf(stdout, "Can't open words file.n"); exit(1); } puts("Enter words to add to the file: press the Enter press at the begining of a line to terminate."); while((fscanf(stdin, "%40s", words) == 1) && (words[0] != '#')) fprintf(fp, "%sn", words); puts("File contents:"); rewind(fp);//返回到文件开始处读取 while(fscanf(fp, "%s", words) == 1) puts(words); if(fclose(fp) != 0) fprintf(stdout, "Error closing file.n"); return 0; }
Code的搬运工V1.0
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)