+ 2

When i entered 555 as input.... Why do 5 came out as output?

include <stdio.h> int main() { char a = getchar(); printf("You entered: %c", a); return 0; }

24th Nov 2019, 10:57 AM
pranay sharma
1 Answer
+ 5
'getchar' only gets one char. So basically, only your first entered char lands in a. If you want to read in more, you need a char array (a place for several chars in a row), and another function that reads more than one char. char a[10]; scanf("%s", a); // s for string printf("You entered: %s", a);
24th Nov 2019, 11:12 AM
HonFu
HonFu - avatar