Hi, could somebody help me with a simple task.
This section of my program asks the user to enter a date, simple enough. The problem is theres nothing to stop the user from entering more than two characters for each part of the date and messing up the rest of the screen
Eg. theres nothing stopping the user entering 12345646435465435354643456431654 in for Day which only wants 12.
Is there any way to 'format' or restrict the amount of letters the user enters or to move to the next section or loop around once two nubers are entered?
Note: I want to keep the 3 variables characters(no integars).
Tab and Display menu are other functions I wrote in my program.
Tab just clears text to the amount passed down to it. Eg. Tab(2) will clears two spaces.
/************************************************** */
char Day[3], Month[3], Year[3];
gotoxy(20,10); cprintf("Enter Date : ");
gotoxy(22,12); cprintf("[____] / [____] / [____]");
gotoxy(23,14); cprintf("[ [DD] / [MM] / [YY] ]");
gotoxy(22,18); cprintf("[ Press RETURN key To Quit ]");
/* Get Day */
do{ // Repeat
gotoxy(24,12); Tab(2); // Clear line of text
gotoxy(24,12); gets(Day); // Get Day for Date
if(strcmp(Day, "") == 0) // If entered RETURN key
Display_Menu(); // Go to Main Menu
}while( (atoi(Day) > 31)||(atoi(Day)<= 0)); // While day is invalid
/* Get Month */
do{ // Repeat
gotoxy(33,12); Tab(2); // Clear line of text
gotoxy(33,12); gets(Month); // Get Month for Date
if(strcmp(Month, "") == 0) // If entered RETURN key
Display_Menu(); // Go to Main Menu
}while((atoi(Month)>12)||(atoi(Month)<=0)); // While month is invalid
/* Get Year */
do{ // Repeat
gotoxy(42,12); Tab(2); // clear line of text
gotoxy(42,12); gets(Year); // Get Year for Date
if(strcmp(Year, "") == 0) // If entered RETURN key
Display_Menu(); // Go to Main Menu
}while((atoi(Year) > 20)&&(atoi(Year) <= 96)); // While year is invalid
/************************************************** */
Steve.