#include <iostream.h>
#include <fstream.h>
void main (void)
{
ifstream inData; //DECLARE FILE STREAM OBJECT
ofstream outData("count.out");
char File_Name[81];
char Ch;
int count_Exe=0;
int count_Comment=0;
int number=0;
cout<<"Please supply the file name:";
cin>>File_Name;
inData.open(File_Name, ios::nocreate);
if (!inData)
{
cout<<File_Name<<"--Error opening file.\n";
}
cout<<"File opened successfully.\n";
while (!inData.eof())
{
inData.get(Ch);
if(Ch=='//') //Check comment line
{
count_Comment++;
outData<<" "<<Ch<<endl;
}else if(Ch=' ') //Check executable line
{
count_Exe++;
outData<<number<<Ch<<endl;
number++;
}else //Check Blank line
{
outData<<endl;
}
}
outData<<"\nHere is the count report\n";
outData<<"Number of executable lines of code:"<<count_Exe;
outData<<"Number of comment lines of code:"<<count_Comment;
cout<<"\nSuccessed!!";
inData.close();
outData.close();
}
I know my problem of this program is checking the command line, execution line, and blank line. I don't know how to write the argument to check these.
Please help me. thanks~