simple question -getch \n and \r

This is a discussion on simple question -getch \n and \r within the C Programming forums, part of the General Programming Boards category; When i do this Code: while( user_char != '\n'){ /*do some stuff*/ } my program wont go out the loop ...

  1. #1
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109

    simple question -getch \n and \r

    When i do this
    Code:
    while( user_char != '\n'){
      /*do some stuff*/
      }
    my program wont go out the loop when pressing the Enter key, wich results in a \n character , although that is with fgets.

    but when i do this.
    Code:
    while( user_char != '\r'){
      /*do some stuff---notice the r*/
      }
    It works perfect now it goes out the loop when pressing the Enter key.

    Any logic explanation behind this?

  2. #2
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109

    Thumbs up

    Well i guess you make these stupid mistakes when you dont have a book or dont take any classes in programming....
    But im pretty sure i wont forget this one, this made me check my code for hours and then finally i found it.

    Thx Salem, you've helped me out
    ***sigh***
    again today.
    *** Salem is my idol , Imma be just like him ***

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