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

Member Avatar for iamthwee

Seems like you just need a file input/output tutorial in c.

Consult google.

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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.