so i have a program that reads in a file and decodes the file then spits out the message. the symbol @ followed by an int will declare what amount i need to shift the alphabet by. i have all of that working fine. my problem is if there isn't an int following the symbol, the program displays an error i made. i need it to discard the rest of the message until it reaches the # symbol. when it reaches that, it will start behaving like normal again. i would appreciate any help.
Need help with c++ - beginning programmer?
if @n occurs on a line by itself, where n is a number or invalid character.
Read the line in.
Call atoi on the string after @.
if atoi returns 0, assume invalid number entered then read characters until the character '#' is encountered.
do {
infile.getline(buffer, 80);
if (*buffer == '@') // if first character = '@'
{
shift = atoi(buffer + 1); // process characters after '@'
if (!shift %26amp;%26amp; errno == ERANGE) // atoi sets errno on invalid value
{
while (!infile.eof() %26amp;%26amp; infile.get() != '#');
continue; // processing file.
}
}
} while (!infile.eof());
Reply:you need to determine if there character after the @ is a digit.
if it is not a digit you have an error, and should read characters until you reach an # or an end of stream.
where exactly is the problem ?
is it the transformation from characters to int ?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment