#include <cctype>
#include <iostream>
usingnamespace std;
bool numFormCheck(char[], int);
int main() {
constint SIZE = 8;
//Customer number:
char custNum[SIZE];
cout << "Enter a customer code in the format ";
cout << "\"LLLNNNN\" (L for Letter, N for Number)\n";
cin.getline(custNum, SIZE);
if (numFormCheck(custNum, SIZE)) { cout << "This code is in the correct format\n"; }
else { cout << "This code is in the wrong format\n"; }
return 0;
}
bool numFormCheck(char custNum[], int size) {
for (int i = 0; i < 3; ++i) {
if (!isalpha(custNum[i])) returnfalse;
}
for (int i = 3; i < size-1; ++i) {
if (!isdigit(custNum[i])) returnfalse;
}
if (!isspace(custNum[size-1])) { returnfalse; }
returntrue;}
the isspace() function I've used in the line before the last line is not working as I expect. For example I give this input "mbn1484[enter]" but isspace believes I've not entered any whitespace characters! and returns false.
Thank you very much. This has solved my problem. Is this part of the Cplusplus.com reference referring to the same thing? That the newline character that I entered was discarded (and then a null character was replaced with it)?
If the delimiter is found, it is extracted and discarded (i.e. it is not stored and the next input operation will begin after it).
The delimiting character is the newline character ('\n') for the first form, and delim for the second: when found in the input sequence, it is extracted from the input sequence, but discarded and not written to s.
[...]
A null character ('\0') is automatically appended to the written sequence if n is greater than zero, even if an empty string is extracted.