Code:
char* getUserInput(char *prompt, char*result)
{
/*char *result;*/
char buff[BUFF_SIZE];
printf(prompt);
result = fgets(buff, BUFF_SIZE, stdin);
if(result == NULL)
{
printf("Error please enter the input again!\n");
}
else if(result[strlen(result)-1] != '\n')
{
readRestOfLine();
}
return result;
}
whats with readrestofline()?
and u have to remember that result is a char * which points to a string,its not a number,so u have to use atoi to convert it to a number.
Code:
unsigned validateMonth(unsigned month, char *prompt)
{
unsigned m;
int flag = FALSE; /* false value*/
do
{
while(flag == TRUE || month<0 || month>12) /* flag 1 for true*/
{
flag = FALSE;
printf("Month error 0 or less or equal to 12 please\n");
getUserInput(prompt);
}
}while(flag !=FALSE);
return m;
}
this bit of code is the most impressive part,but it will work.
alrite m was never assigned anything? why have the function return an unsigned? or perhaps u r later going to have a use for a m?
Code:
unsigned getMonth()
{
/*** declare variables*/
unsigned tmpMonth;
int valid = 0;
char *prompt = "Please enter a month between 0 - 12 !\n";
char *month;
unsigned valMonth;
month = getUserInput(prompt);
tmpMonth = validateMonth(valMonth, prompt);
return EXIT_SUCCESS;
}
>tmpMonth = validateMonth(valMonth, prompt);
valMonth was never assigned anything.
change the month to a number using atoi and then assign it to valmonth.
and i suppose u have read a bit too much on MODULARITY.