Hi! how do i use asc characters in C? because i need to program to know the user pressed <enter> key...
thanx!
Hi! how do i use asc characters in C? because i need to program to know the user pressed <enter> key...
thanx!
> how do i use asc characters in C?
Do you mean ASCII?
A return character is written in C as '\n'
Like
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.
I think the actual ASCII value for '\n' is 0xa (10 decimal), so you could probably do:
int a;
if((a = getchar()) == 0xa) {
blah;
}
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
> 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.