Hello,
I'm compiling with Dev-c++ 4.01. This routine accepts
six alphanumeric characters, e.g. A1B2C3, and is
part of a mailing list program.
The program compiles without errors. When run it
seems to skip over the character functions (no input),
and prints the error handling statement:"The ZIPcode
must be alphanumeric only."
What am I doing wrong? Am I omitting something,
or is the design faulty?
This is what I'm able to do.
Thank you.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
/*Prototype*/
char err_msg(char msg[]);
char getzip(char zipcode[]);
int main();
char err_msg(char msg[]) {
printf("\n\n%s\n", msg);
fflush(stdout);
return;
}
char getzip(char zipcode[])
{
int ctr;
for(ctr = 0; ctr < 6; ctr++)
{
zipcode [ctr] = toupper(zipcode [ctr]);
if(! isalpha(zipcode [ctr]))
{
if(! isdigit(zipcode[ctr]))
{continue;}
else
{
err_msg("The ZIPcode must be alphanumeric only");
break;
}
}
}
}
int main()
{
int ch;
char zipcode[7]; /*Extra null character.*/
do
{
ch = 0;
printf("Enter ZIPcode");
fgets(zipcode, 7, stdin);
while(getchar() != '\n');
ch = 1;
}
while(ch);
system("PAUSE");
return;
}