-
Help Me...
my question is how to check if the statement begin with '//' & blank line?
-
Pygmy Monkey
-
//some command lines....
(blank line)
execution lines...
....
....
(blank line)
//some command lines....
-
Pygmy Monkey
I'm not sure what you mean.
You want to check if there is a empty line beginning with // in the code above a statement?
-
i want to check each line of code....
weather begin with //, blank line, and execution line...
-
I think he/she means: how to check for pairs of // and blank line.
Pair 1:
// comments
(blank line)
Pair 2:
(blank line)
// comments
What you could do is remember the state of the previous line and compare it with the current line. If previous was BLANK_LINE and current line is COMMENT_LINE, then you've got pair 2, and if previous was COMMENT_LINE and current is BLANK_LINE the you've got pair 1.
Don't know if that is what you mean, just guessing. Please try to be a bit more specific.
-
Here is the code i am trying to do...
while(inData.eof())
{
inData.get(Ch);
if((strcmp(Ch,"//")==0)) //check line begin with // as comment
{
count_Comment++;//count comment lines
outData<<" "<<Ch;
}else if ((strcmp(Ch," ")==0) && )//check lines begin with /0 and not a blank line
{
count_Exe++;//count execution lines
outData<<number<<Ch;
}
else //otherwise, it is a blank line, so just prink it out, not add number or something else.
outData<<Ch;
}
-
First Ch should be declared something like:
char Ch[120];
>while(inData.eof())
>{
>inData.get(Ch);
You want a whole line. This only reads a single character. Try getline() instead:
inData.getline(Ch,120);
>if((strcmp(Ch,"//")==0)) //check line begin with // as comment
If you want to compare the first two characters, use strncmp():
if((strncmp(Ch,"//",2)==0)) //check line begin with // as comment
-
will you be able to see that?, isn't it so that the compiler ignorres
them?
Popular pages
Recent additions