Get the FREE certificate on C, C++, Java, Python, Perl, PHP, SQL, Linux & Javascript!  

CppBuzz.com
  
Home C C++ Java Python Perl PHP Spring SQL Javascript Linux

You are here : Home » Program to read a text file line by line

C program to read text file (read file line by line)

/*
Program to read a text file line by line
Author: CppBuzz
Date: 17th Nov 2017
*/

#include <stdio.h>

int main(int argc, char* argv[])
{
//pass the filename as argument
char const* const fileName = argv[1]; 
FILE* file = fopen(fileName, "r"); 
char line[500];

while (fgets(line, sizeof(line), file)) {
printf("%s", line); 
}
fclose(file);
return 0;
}