str/char 101 question

Oct 14, 2009 at 4:20am
Hi
I read a program which has a char array : char str[80]. The user is supposed to input a string which can be less than 80 char. After that use gets(str) to read the string.

My question is 1. does gets(str) refill all the char in "str" or just up to the length of the input? 2. If I use cout<<str, does it print out all 80 chars (including the empty chars?)
Oct 14, 2009 at 4:25am
I believe it reads as much as it wants; until the user enters a '\n' character. I assume that the array is null-terminated; if so, cout should print up until NUL character. Otherwise, it'll probably print until it finds one or the program crashes because its reading data it's not allowed to.
Oct 14, 2009 at 12:08pm
Oct 14, 2009 at 2:46pm
Topic archived. No new replies allowed.