+ 2

Scanf or getchar? C Language

Hi, im learning the language c but I get condfused because i dont understand Well the differences bettwen both of this functions. How do you reccomend to use??

24th Apr 2018, 12:03 AM
Franco Fonzo
Franco Fonzo - avatar
5 Respuestas
+ 5
getchar() just gets a single character, whereas scanf() can get different types. e.g. int i; scanf("%d", &i) double r; scanf("%f", &r); https://stackoverflow.com/questions/3640604/c-getchar-vs-scanf
24th Apr 2018, 12:13 AM
Emma
+ 1
and can i use a type of get but instead of one char to More???
24th Apr 2018, 1:38 AM
Franco Fonzo
Franco Fonzo - avatar
+ 1
scanf() gets multiple characters (strings), and attempts to convert them into the correct type, see my previous answer. Here's the documentation for scanf() http://man7.org/linux/man-pages/man3/scanf.3.html
24th Apr 2018, 9:49 AM
Emma
0
Use getchar when you want one character input. You can use scanf for variety of inputs but not get char.
24th Apr 2018, 1:26 AM
Akib
Akib - avatar
0
Hi Kechu, you can use scanf() for printing one or more characters.
24th Apr 2018, 4:20 AM
ThiemTD
ThiemTD - avatar