How to read / parse input in C? The FAQ
I have problems with my C program when I try to read / parse input.
Help?
This is a FAQ entry.
StackOverflow has many questions related to reading input in C, with answers usually focussed on the specific problem of that particular user without really painting the whole picture.
This is an attempt to cover a number of common mistakes comprehensively, so this specific family of questions can be answered simply by marking them as duplicates of this one:
scanf("%d", ...)
/ scanf("%c", ...)
fail? gets()
crash? The answer is marked as community wiki. Feel free to improve and (cautiously) extend.
The Beginner's C Input Primer
stdin
or any other stream open for reading, ever Text mode vs. Binary mode
A "binary mode" stream is read in exactly as it has been written. However, there might (or might not) be an implementation-defined number of null characters ('