+ 1

If an integer value is to be entered through keyboard for direct arithmetic operation, what function should be use? gets,scant ?

If an integer value is to be entered through keyboard for direct arithmetic operation, what function should be use? gets() getchar() scanf() getstring()

21st Nov 2018, 3:43 PM
ricky yeung
ricky yeung - avatar
2 Réponses
+ 4
If you mean to read the input as an expression e.g. "5*4/3-2+1", rather than numbers then you can use scanf() with %s as format specifier. Having a sufficient sized buffer prepared, you can read the input as string (char array) then you can parse the expression and process them piece by piece. I read somewhere that gets() is considered unsafe, and getstring() is non standard (cmiiw).
22nd Nov 2018, 8:35 AM
Ipang
0
gets()
29th Nov 2018, 2:21 PM
threeno
threeno - avatar