Thread: asc characters

  1. #1
    Dani
    Guest

    Talking asc characters

    Hi! how do i use asc characters in C? because i need to program to know the user pressed <enter> key...
    thanx!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > how do i use asc characters in C?
    Do you mean ASCII?

    A return character is written in C as '\n'

    Like
    &nbsp; if ( ch == '\n' )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    16

    Alternative

    I think the actual ASCII value for '\n' is 0xa (10 decimal), so you could probably do:

    int a;
    if((a = getchar()) == 0xa) {
    blah;
    }

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    If anyone really cares...
    When you hit the ENTER key two values are written, a carriage return and line feed. The two values are 13 and 10.

    Just a FYI

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > When you hit the ENTER key two values are written, a carriage return and line feed.
    This depends on your OS.

    But if you stick to the ANSI functions for reading input, then the newline will always be '\n', no matter how the underlying operating system chooses to represent it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 07:35 AM
  3. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  4. How do you check how many characters a user has entered?
    By engstudent363 in forum C Programming
    Replies: 5
    Last Post: 04-08-2008, 06:05 AM
  5. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM