C语言_将字符串写入文本文件

假设我要在我的桌面新建一个"love_note.txt"文件,并将我从键盘输入的字符串写到这个文件中。应该怎样写C代码?

FILE *fp; char ch; fp=fopen("C:\\Documents and Settings\\Administrator\\桌面\\love_note.txt","w+"); if(fp == NULL) { printf("Cannot open file strike any key exit!"); exit(1); } while(1) { scanf("%c",&ch); if(ch =='#') break; fprintf(fp,"%c",ch); } fclose(fp); }
温馨提示:答案为网友推荐,仅供参考
相似回答