C examples for File:File Operation
Reads each line from the file and outputs it to the screen
#include <stdio.h> #include <stdlib.h> FILE * fptr;//ww w .j av a 2 s. co m int main() { char fileLine[100]; // Will hold each line of input fptr = fopen("C:\\test\\BookInfo.txt","r"); if (fptr != 0){ while (!feof(fptr)){ fgets(fileLine, 100, fptr); if (!feof(fptr)){ puts(fileLine); } } }else{ printf("\nError opening file.\n"); } fclose(fptr); return(0); }