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.


Index


Last Updated 23 December 2000 by Nik Swain (email: nikswain@oocities.com)

This page hosted by Geocities Icon Get your own Free Home Page