Originally Posted by
matsp
No, it means you can have 29 characters plus the terminating zero. If you have 31 characters, you have gone 2 characters over.
The other part of the problem is that scanf() stops as soon as it sees a blank/newline/tab (or other "whitespace").
There are two possible solutions:
Change the format string of your "%s" to "%29[^\n]" - that means "accept up to 29 of the characters specified in the brackets. The ^ means "invert", so we are basically saying "accept any input except (or up to) newline".
The second option is to use fgets(string, size, stdin) - this reads a line of text, and you can use sizeof or some such to to define "size" - it will not read beyond size. You will have to remove the newline at the end of the string tho', as fgets() reads UP AND INCLUDING the newline. scanf() leaves newlines until the next scanf() - which also means you have to get rid of the OLD newline that is from the previous scanf() before using fgets().
You can check the FAQ for "how to clear the input buffer".
--
Mats