fopen

Hello people, I am just starting C programming and I am having trouble with fopen.
My current text works fine but I can't figure out how to keep the result. Here is my code.
EDIT: I messed up on the first question (sorry coder777) here is a simpler more easy to understand version.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
FILE * pFile;
pFile = fopen ("myfile.txt","w");
if (pFile!=NULL)
{
fputs ("Hello.\n",pFile);
fclose (pFile);
}
exit (0);
}





So say I want to put Hello. in myfile.txt BUT if I want to keep that result and put something else in too and be able to see both of them in myfile.txt, how would I do that? Don't worry it's not homework.
Last edited on
Hello victortacos,

This line
printf("%i,%i,%i,%i,%i.\n",rand1,rand2,rand3,rand4,rand5);.",pFile);

should be
fprintf(pFile, "%i,%i,%i,%i,%i.\n",rand1,rand2,rand3,rand4,rand5);

not the 'fprintf' and the position of 'pFile'
Topic archived. No new replies allowed.