I want a user to input text, which can include spaces, tabs etc and store it into char array. User can input longer text than my array size. Smaller code preferred. I need to handle that without overflow. Best way I could find was described at http://www.daniweb.com/software-development/c/tutorials/45806/user-input-strings-and-numbers-c , but upon entering a longer text than my first array size it overflows to second array and doesn't ask for input.
If you have any link to a tutorial which explains how to handle garbage user input without complicated code, help would be much appreciated.
Sorry for my english.
You have to consume the entire first line before reading in the second one.
BTW:
The following has nothing to do with your problem:
1. You're mixing C stdio with C++ iostreams. This may confuse your IO because both systems use different IO buffers. See http://www.cplusplus.com/reference/ios/ios_base/sync_with_stdio/ for help or better: Only use one of those systems.
2. You want to write a function to read in your character arrays to avoid writing the same code multiple times (line 16-26 and 28-38).
staticconstchar EOL = '\n'; // May be defined as '\r' on Macs
/*
================
skipLine
================
*/
void skipLine()
{
int c;
while ( (( c = fgetc( stdin )) != EOF ) && ( c != EOL ) )
;
}