I saw some weird behavior with my C++ function whose work is to simply put 'n' ones(1).
char *getSpaces(int n) {
char s[50];
int i = 0;
for(i=0; i<n; i++) {
s[i] = '1';
}
s[i] = 0;
return s;
}
When I do fout<< getSpaces(20)
, I get following output in the file :-
1111111111SOME_WEIRD_CHARACTERS_HERE
Can anybody explain this?
P.S. I am using codeblocks IDE on windows platform.