当我使用fputs()直接在文件中存储字符数组时,它将其存储在文件中:
ÈLwìþ(那是为什么?
#include <stdio.h> int main() { FILE *p; p=fopen("pa.txt","w+"); char name[100]; printf("Enter a string :"); fputs(name,p); fclose(p); getchar(); return 0; }当我使用scanf()或gets()名称输入时, gets()存储正确的文本,但是当使用fputs() ,它会以不寻常的格式存储。 为什么会这样?
When I used fputs() to directly store a character array in a file, it stored this in the file:
ÈLwìþ(Why was that?
#include <stdio.h> int main() { FILE *p; p=fopen("pa.txt","w+"); char name[100]; printf("Enter a string :"); fputs(name,p); fclose(p); getchar(); return 0; }When I take input in name using scanf() or gets(), the correct text is stored but when directly use fputs() is used it stored in an unusual format. Why does this happen?
最满意答案
当我使用scanf()或gets()名称输入时, gets()存储正确的文本,但是当直接使用fputs() ,它会以不寻常的格式存储。 为什么会这样?
在使用fputs写出之前,您还没有从stdin读取数据。
使用:
fgets(name, sizeof(name), stdin);然后:
fputs(name, p);When I take input in name using scanf() or gets() correct text is stored but when directly fputs() is used it stored in unusual format. Why this happens ?
You haven't read the data from stdin before writing it out using fputs.
Use:
fgets(name, sizeof(name), stdin);and then:
fputs(name, p);更多推荐
发布评论