Assuming you want to read in a string as opposed to a single character, I would highly recommend using fgets
instead of scanf
to read your input, as it will ensure that you never get a buffer overflow of any sort, as far as I recall.
Also, as others have said, you will first need to allocate more than one character for the answer, either by statically allocating it or doing it dynamically with malloc
and free
. Assuming you want to save the answers somewhere, doing dynamic allocations would be necessary. If you only need it one time, allocating it statically like char answer[100];
would suffice. Although I would recommend putting something like #define BUFFER 100
at the top of your file, and allocating it like char answer[BUFFER];
instead.