Reputation: 41
so i am learning c today. I wrote some code to get input with getchar() and save it in a variable to understand how the input to integer works.
So if give a input with my keyboard like "1" and press enter i get a Value of 4910 back. I expected the value of 49 cause the decimal Ascsii code for the Char "1" is 49. Where does the 10 come from?
#include <stdio.h>
/* count lines in input */
main()
{
int c;
while ((c = getchar()) != EOF)
printf("%d",c);
}
Upvotes: 3
Views: 184
Reputation: 44838
10 is the ASCII code of the newline character, '\n'
. You input this character when you hit Enter.
Upvotes: 7