Return to Snippet

Revision: 45048
at April 22, 2011 21:59 by imprfikt


Initial Code
#include <stdio.h>

void main()
{
    char str[200];
    FILE *fp;

    fp = fopen("test.txt", "r");
    if(!fp) return 1; // bail out if file not found
    while(fgets(str,sizeof(str),fp) != NULL)
    {
        // strip trailing '\n' if it exists
        int len = strlen(str)-1;
        if(str[len] == '\n') 
            str[len] = 0;
        printf("\n%s", str);
    }
    fclose(fp);
}

Initial URL

                                

Initial Description

                                

Initial Title
Read file line by line

Initial Tags
file

Initial Language
C