Write a parsing program (something that splits a bigger data type ie. a ISBN number to a more manageable datatype ie. an array of char[]). Load in the ISBN number from the file, and make sure it doesn't contain more than 3 dashes (-), that it only contains numbers (other than dashes and possible X checksum value) and that it doesn't start or end with a dash. Then, if all those checks pass, make sure the final digit is the proper checksum (using the method you described). I'm not sure how much clearer this can be made!
hmmm well have a function similar to this (im not going to right main or any declarations)
bool Parse(char const * szString)
{
bool bFail(false), bWasDash(false);
int checksum(0), realchksum(0), dashes(0);
for (int i(0); i < strlen(szString); i++)
{
if (szString[i] != '-')
bWasDash = false;
if (isdigit(szString[i]))
checksum += szString[i] - 30; //numbers start at 30 on ascii chart
else if (i == strlen(szString) && tolower(szString[i]) == 'x')
realchksum = 10;
else if (i == strlen(szString) && isdigit(szString[i]))
realchksum = szString[i] - 30;
else if (((i == 0 || i == strlen(szString) || bWasDash) && szString[i] == '-') || isalpha(szString[i]))
{
bFail = true;
break;
}
else if (szString[i] = ='-')
{
bWasDash = true;
dashes++;
}
//add more checks here i dont know/care if i got them all
}
//now check the checksum
if (checksum != realchksum)
bFail = true;
return bFail; //returns true if its a bad number
}
I don't know if this will actually run, i didnt compile it. And it probably doesn't cover all of the checks. And you'll have to figuire out the file i/o part - since that's pretty elementary. I really don't like writing whole functions for people, but since you don't understand english very well, maybe you'll understand code better.