0

hi all,
Suppose, I have a string stored in a character array. I want this string to be stored in a file. If I do fopen and use the write mode ,the contents of this file will be junk.. How can I store the string as it is inside the file?
please help,
thanks

3
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by Ancient Dragon
0

post code. Since you use fopen() I assume this is a C and not C++. After fopen, just use fprintf() then fclose().

char strp[] = "Hello World";
FILE* fp = fopen("myfile.txt","w");
fprintf(fp,"%s\n",strp);
fclose(fp);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.