【发布时间】:2011-11-13 22:21:44
【问题描述】:
我正在开发一个程序,将用户输入写入文件,然后在文件中搜索特定记录并将其输出到屏幕。 我尝试使用 fgets 和 fputs 但没有成功
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main ()
{
FILE *fileptr;
char id [30];
char name [47];
char amt[50];
int i;
fileptr=fopen("C:\\Users\\Andrea\\Documents\\Tester.txt","w");
if (fileptr == NULL) {
printf("File couldn't be opened\n\a\a");
fclose(fileptr);
exit(0);
}
printf("Enter name: \n");
fscanf(fileptr,"%c",name);
fputs(name,fileptr);
fclose(fileptr);
printf("File write was successful\n");
return 0;
}
【问题讨论】:
-
发帖过程中似乎出了点问题。请点击
edit发布您的程序(并可能描述什么是“效果不佳”)。 -
你能告诉我们你试过的代码吗?
-
没有附加代码。请改进您的信息。
-
对不起,我已经添加了代码
-
如果是
null,你为什么要关闭fileptr?
标签: c