hi all... i m working on a C++ prgm with following definition:
Program Definition: Write a program to perform the following on a source file of any c++ program(File shud be included):
1. Count the line of code (LOC) of a source code file
2. Count the total number of statements. (i.e. Semicolons)
3. Count the total number of Logical Statements. (i.e. Closing Braces)
4. Count selected Key words(if,else,do,while etc).
5. Blank lines and comments should be removed from the LOC.
Now i m able to do the first 3 conditions, but the remaining 2 options I m not able to do... so pls anyone of u know how to work on files with string comparision then pls help me in this.
I have written the following code:
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
void main()
{
clrscr();
int cnt=0,cnt1=0,cnt2=0;
ifstream OpenFile("prog21.cpp");
char ch;
while(!OpenFile.eof())
{
OpenFile.get(ch);
if(ch==10)
cnt++;
if(ch==59)
cnt1++;
if(ch==125)
cnt2++;
}
cout<<"\nTotal Lines of code is : "<<cnt+1;
cout<<"\nTotal Statements are : "<<cnt1;
cout<<"\nTotal Closing Braces are: "<<cnt2;
OpenFile.close();
getch();
}