Can't write getchar, gets like below?if so, why? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can't write getchar, gets like below?if so, why?

char a; getchar(a); And, Char a[100] = gets(a);

26th Feb 2019, 3:21 PM
Mashud Iqbal
Mashud Iqbal - avatar
1 Answer
+ 3
Hi! The function prototype of getchar() is: int getchar ( void ); That's why getchar(a); is incorrect... it should be: a = getchar(); And when you try to do: char a[100] = gets(a); Throws an error because char a[100] can be initialized at compile time but not at runtime; gets(a) returns a string from user... (at runtime)
26th Feb 2019, 3:57 PM
unChabon
unChabon - avatar