How to convert C++ code to C.
Write a program in C that asks a user for the name of a file. The program should display the first 10 lines of the file on the screen (the "head" of the file). If the file has fewer than 10 lines, the entire file should be displayed, with a message indicating the entire file has been displayed.
\//Run the program using visual studio 2010 vc++
/**
*This program ask the user to enter the name of the text file
*and displays the ten lines of the file and if the file having less than 10 line than
*display the output that the total file has been displayed
*/
//Header files
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
//start of main funtion
int main()
{
//variable declaration
string filename;
char ch;
//char line[80];
//create file stream object to the class fstream
fstream fin;
//ask for file name
cout<<"Enter a filename"<
cin>>filename;
//open that file in read mode
fin.open(filename,ios::in);
//check the file is opened successfully
if(!fin)
{
cout<<"Error while opening file "<
}
else
{
int counter=0;
//checking for end of the file
while((ch=fin.get())!=EOF && counter<=10 )
{
//getline funtion to take one line at a time
if(ch=='\n' )
{
counter++;
}
//display to the screen
cout<
}
//display the message if number of lines are less than ten
if(counter<10)
{
cout<<<"------------------------------"<
cout<<"ENTIRE FILE HAS BEEN DISPLAYED"<
}
}
//to pause the output
system("pause");
return 0;
}
//end of main function
Please help. Thanks.