+ 3

Help Please, Basic Input and Output C program

#include <stdio.h> int main() { char a[100]; char b; printf("Hello world!\n"); printf("Enter a character : "); b=getchar(); printf("You entered : %c\n", b); printf("Enter a word : "); gets(a); printf("You entered: %s", a); return 0; } So, the purpose of that program is to ask for a character input and then display the character. After that, the program then prompt the user to input a word and displayed them. Unfortunately, it doesn't work the way is supposed to. What went wrong here ?

28th Aug 2019, 7:05 AM
Moh. Ifan Gitawa
Moh. Ifan Gitawa - avatar
3 Answers
+ 9
Sololearn IDE haven't facility to type input one by one . You have type it all just for once using space and new line
28th Aug 2019, 9:32 PM
Aung Thiha
Aung Thiha - avatar
+ 7
Interactive input does not work on code playground for non web codes. You need to enter all inputs at once, separated by newlines.
28th Aug 2019, 7:28 AM
Sonic
Sonic - avatar
+ 1
Try having the input for the word first and the input of the character second. #include <stdio.h> int main() { char a[100]; char b; printf("Hello world!\n"); printf("Enter a word : "); gets(a); printf("You enterded : %s\n", a); printf("Enter a character : "); b=getchar(); printf("You enterded : %c\n ", b); return 0; }
30th Aug 2019, 2:49 AM
Kireii
Kireii - avatar