+ 1

Difference between scanf(), get() and getchar()?

How do i know when to use each one in C?

31st Jan 2023, 11:50 AM
Kingdavid Christian
Kingdavid Christian - avatar
3 Réponses
+ 2
Kingdavid, EOF is end-of-file (don’t really need to worry about this unless redirecting input to stdin). Gets will grab the input up to the newline, so it includes whitespace. You’ve also got fgets, which unlike gets will stop at an EOF.
31st Jan 2023, 12:13 PM
DavX
DavX - avatar
+ 2
Getchar grabs the first character from the std input stream (stdin) - keyboard entry. Only one character. Scanf will grab input up to a whitespace, new line of EOF. …do you mean gets()?
31st Jan 2023, 12:01 PM
DavX
DavX - avatar
0
DavX yes i mean gets(), and what's EOF?
31st Jan 2023, 12:06 PM
Kingdavid Christian
Kingdavid Christian - avatar