C / C++ Tutorial Part 6
File access :
// Reading text from a file
FILE * phFile = fopen("myfile.txt","r")
if(phFile)
{
char acOut[255] = {0};
while(! feof(phFile)
{
fgets(acOut,1,sizeof(acOut),phFile);
printf( "%s\n". acOut );
}
fclose(file);
}
To write to a file you would open the file using "w" instead of "r" and use fputs to write strings although fprintf is quite handy.
This page hosted
by Get
your own Free
Home Page