Thread: if statement.

  1. #1
    Unregistered
    Guest

    Question if statement.

    is that right to use if statement to check....

    inFile.open(FileName,ios::in);
    inData.get(Ch);
    if(Ch=='//') //Q?? check the source begin with '//'
    {
    ......
    }



    source:
    //some command;

  2. #2
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    i think its ok to use if statements, i dont know how else you are going to check..

    >>if(Ch=='//')

    in char datatypes ( == ) work for just one char not 2

    You'll have to use probably

    inData.get(Ch,2,'\n');

    and then use strcmp to check

    if((strcmp(ch,"\\")==0)
    {
    ---
    ---
    }
    -

  3. #3
    Unregistered
    Guest
    the first \ is the is the escape operator as which allows you to use \n to mean newline or \t to mean tab or \b to mean backspace or \* to mean start of comment section, etc. Therefore to test to see if there is a single \ in a string or if it is stored in a char variable you need to say something like:

    char ch == //whatever;
    if(ch == '\\')

    However, I don't think the same holds for /. Otherwise you couldn't use the / as indicative of division operator. Therefore // should be a string of two / and can't be evaluated using the == operator but will need to checks for chars or strcmp().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 05:19 AM
  2. Meaning of this statement?
    By @nthony in forum C Programming
    Replies: 7
    Last Post: 07-16-2006, 02:57 AM
  3. If Else statement problem
    By doofusboy in forum C Programming
    Replies: 2
    Last Post: 11-09-2005, 07:18 AM
  4. if/break statement
    By Apropos in forum C++ Programming
    Replies: 7
    Last Post: 02-22-2005, 02:33 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM