Open a file for read : File Open « File « C / ANSI-C






Open a file for read


#include "stdio.h"

int main() {
    FILE *fp;
    
    int letter;

    if( ( fp = fopen( "my.txt", "r")) == NULL) {
        puts("Cannot oepn the file");
        exit( 0 );
    }
    while( ( letter = fgetc( fp ) ) != EOF)
        printf("%c",letter);
    fclose(fp);
}


           
       








Related examples in the same category

1.Get file name from command line and open the file
2.Open a file and close it
3.Reopen a file
4. Open a file: how to use fopen
5. Reopen a stream with a different file and mode: how to use freopen