Pages

Monday, January 25, 2016

C program to read file line by line.

This program will read and print content of the "test.txt" file. 

Note: Save source code (.c) file and "test.txt" file in same folder.

#include<stdio.h> 
int main()
{
 FILE *f1, *fopen();
 char str1[80];
 
 f1 = fopen("test.txt","r");

 while(fgets(str1,80,f1)!=NULL)
 {
  printf("%s",str1); 
 }
 fclose(f1);
 return 0;
}

No comments:

Post a Comment