一个文件输入问题,高手来看下
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void main()
{
FILE *fp;
char str[11];
if((fp=fopen("11.txt","wt+"))==NULL)
{
printf("Cannot open file strike any key exit!");
getch();
exit(1);
}
printf("input a string \n");
fputs(str,fp);
fclose(fp);
}
我想不用SCANF()输入字符,请问有什么别的函数能坐倒吗?
[解决办法]
- C/C++ code
#include <stdio.h> #include <stdlib.h> int main() { FILE *fp; char str[11]; if ((fp=fopen("11.txt","wt+"))==NULL) { printf("Cannot open file strike any key exit!"); getch(); exit(1); } printf("input a string \n"); gets(str); /*here*/ fputs(str,fp); fclose(fp); return 0;}