Help Me...

This is a discussion on Help Me... within the C++ Programming forums, part of the General Programming Boards category; my question is how to check if the statement begin with '//' & blank line?...

  1. #1
    Unregistered
    Guest

    Help Me...

    my question is how to check if the statement begin with '//' & blank line?

  2. #2
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    ahh....what statement?

  3. #3
    Unregistered
    Guest
    //some command lines....
    (blank line)
    execution lines...
    ....
    ....
    (blank line)
    //some command lines....

  4. #4
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    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?

  5. #5
    Unregistered
    Guest
    i want to check each line of code....
    weather begin with //, blank line, and execution line...

  6. #6
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    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.

  7. #7
    Unregistered
    Guest
    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;
    }

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    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

  9. #9
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    will you be able to see that?, isn't it so that the compiler ignorres
    them?

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21