If the input is smaller than 128 characters, I have no problems. But if the input is longer than 128 characters, the loop is passing through all the time and I get spammed with: ERROR: You must type something. I can't do something until I close the console and finish the program.
It seems like the cin.getline() function is not called and the command variable is always empty.
My plan was, that the command was too long and I want a new input...
Where is the problem???
...
#define MAX_COMMAND_LENGTH 128
int main()
{
char command[MAX_COMMAND_LENGTH];
while (1)
{
cout << "\nSend command: ";
cin.getline(command, MAX_COMMAND_LENGTH);
if ((strlen(command) == 0))
{
cout << "ERROR: You must type something." << endl;
continue;
}
else if (strlen(command) > MAX_COMMAND_LENGTH - 2)
{
cout << "ERROR: The command may only be 128 characters long." << endl;
continue;
}
...
}
return 0;
}
I also tried something with: cin.ignore(MAX_COMMAND_LENGTH, '\n');, but it does not work :S