c - When fputs is used directly for writing character array in a file, a different format of text is stored -


when used fputs() directly store character array in file, stored in file:

Èlwìþ(  

why that?

#include <stdio.h>  int main() {     file *p;     p=fopen("pa.txt","w+");     char name[100];     printf("enter string :");     fputs(name,p);     fclose(p);     getchar();     return 0; } 

when take input in name using scanf() or gets(), correct text stored when directly use fputs() used stored in unusual format. why happen?

when take input in name using scanf() or gets() correct text stored when directly fputs() used stored in unusual format. why happens ?

you haven't read data stdin before writing out using fputs.

use:

fgets(name, sizeof(name), stdin); 

and then:

fputs(name, p); 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -