Thread: while((ch = getchar()) != '#') and while (ch = getchar() != '#')

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    11

    while((ch = getchar()) != '#') and while (ch = getchar() != '#')

    Hello,
    What is the difference between:
    while ((ch = getchar()) != '#')

    and:

    while (ch = getchar() != '#')

    Thank you.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The second one calls getchar, checks whether or not it's equal to '#', and assigns true or false (i.e., 1/0) to ch. The first assigns the char to ch, and then checks equal to '#'.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    11

    Thank you

    Ah ha, thank you.

  4. #4
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by mashour06 View Post
    Hello,
    What is the difference between:
    while ((ch = getchar()) != '#')

    and:

    while (ch = getchar() != '#')

    Thank you.
    the precedence of '!=' is greater than '=', that's why this happens.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

Popular pages Recent additions subscribe to a feed