C++ char array characteristic: why does a string stop before the end of the array?
When you enter your string with cin it automatically adds a at the n+1 element of the string (n being the size of your string). String operated functions like cout or fopen will only read up to that point. To test this theory you can enter a string 10 characters long, say, and then manually change the 11th character to something else. Then manually add a at say the 20th character and print out the string. Youll get a 20 char string with the chars from 10 to 20 being any gibberish.
fopen() uses c-string which by definition is a list characters ending to