Thank you for your help so far, and I think I have it mostly working. My only problem is getting it to end... can someone help me make the program stop when I just hit enter? Using a condition for pcode[0] != EOF or '\n' doesn't seem to do anything... those probably can't be entered into an array anyway, right? Any help would be appreciated... I can never seem to get EOF to work for me.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char pcode[20];
int banned=0, valid=0, invalid=0;
printf( "\nWelcome to the Product Code validator.\n" );
printf( "Please enter your Product Code. It should consist of numbers (N) and letters (L) in the folowing format: \n" );
printf( " LLLNNNNLNL-NN\n" );
while( pcode[0] != EOF )
{
printf( "\nEnter your code here: " );
scanf( "%s", &pcode );
printf( "%s\n", &pcode );
if( strlen (pcode) < 13) /* check if input is too short*/
{
printf( "Invalid - product code is too short\n" );
invalid++;
}
else if( strlen (pcode) > 13) /* check if input is too long*/
{
printf( "Invalid - product code is too long\n" );
invalid++;
}
else if( ( (pcode[3]) < '0' || (pcode[3]) > '9' ) || ((pcode[4]) < '0' || (pcode[4]) > '9' ) || ((pcode[5]) < '0' || (pcode[5]) > '9' ) || ((pcode[6]) < '0' || (pcode[6]) > '9' ) || ((pcode[7]) < '0' || (pcode[7]) > '9' ) )
{
printf( "Invalid - Region is non-numeric\n" );
invalid++;
}
else if( ((pcode[9]=='R')||(pcode[9]=='r')) && (pcode[3]>='2') ) /* check if input is from banned region*/
{
printf( "Banned code\n" );
banned++;
}
else
{
printf( "Valid code\n" );
valid++;
}
}
printf( "You entered %d banned code(s), %d invalid codes, and %d valid codes. ", banned, invalid, valid );
printf( "End of Program\n" );
return 0;
}