[SOLVED] Unexpected return from cin.getline() in C++
I have this problem that when I use getline() function to input a char array it also inserts other characters, that are not constant and change every time I run the program. I do realize it is most likely because of some kind of overflow happening, and it just takes numbers from the RAM. But is there a possibility to fix that? (Program is supposed to reverse a string and remove any non-letters, excluding spaces) Here is my program: #include <iostream> #include <ctype.h> #include <string> using namespace std; int main() { string decoded = ""; char text[100]; cin.getline(text,sizeof(text)); for(int i = sizeof(text)-1; i >= 0; i--){ if (isalpha(text[i]) || text[i] == ' ' ) decoded.push_back(text[i]); } cout << decoded; return 0; }