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()
orgets()
correct text stored when directlyfputs()
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
Post a Comment