1
I need to check if a date is valid or not in C, and for this I will have a function called verificarData
that will be passed to it the user input and will check whether or not it is a valid date.
But I’m in doubt, because I’ll have to break this to pieces data
to check whether it contains :
Contains two bars between date
If the day is between 1 and 31.
If the month is between 1 and 12.
Year between 1900 and 2100
If month is 04, 06, 09 or 11, day can be maximum 30;
If month is 02, day can be maximum 28;
If year is leap and month is 02, day can be maximum 29.
Which is better to use in case ? Use vetor
or even char
and try to break the date and do the proper checks, and if I can use with char, how to break it into pieces to check ?
For example, if the user enters the following value :
Input : 20/03/2009
How can I break for you to stay, 20/
, 03/
and 2009
separated so I can check ?
I also need to check if the day, month and year are numerical, but as I’m putting bars with numbers I can’t use the function isdigit
to verify.
Example :
if(isdigit(data)) {
printf("São numéricos.");
}
else {
printf("Não são numéricos.");
}
But it returns as if they are not numbers even the user putting the day, the month and the year with numbers, because because of the bars, it returns as if it were a string. How can I check and return saying if they are numbers or not correctly ?
for each of the cases, what is the expected result? Some kind of message to the user or are only validations?
– mercador
Only validations, a message will be sent to the user only if after checking whether or not the date is validated.
– Monteiro