cin.get command with three arguments. The problem that occurs is if somebody simply presses enter with no value entered the program seemingly goes into an infinite loop rather than entering the '\0' character into the 0 element of the array. The code I've been using for entry is below
- Code: Select all
cout << "Second line:";
cin.get(incr->secondadd, 20, '\n');
The cin.ignore is there incase somebody enters more than 19 characters into the array. It works in Dev-Cpp (which uses a GNU compiler, I thought they'd have the same quirks even across platforms ) in windows but on trying to run it in Ubuntu I get the problem above. The cin.getline command solves the one problem (that being entering '\0' on an empty entry) but leaves me with an infinite loop even with the cin.ignore command if more than 19 characters are entered (the cin.ignore also requires a enter each time since getline flushes the '\n' character from the buffer).
If anyone has a solution that enters '\0' into secondadd on an empty entry while also truncating the entry should it exceed 19 characters I will be grateful. The '\0' is necessary since I use it later to skip an empty field during output.
//edit - nevermind I found a solution //