Originally Posted by
bazzano
I am using sscanf() function to read in the values but as soon as it hits the sscanf() function it reads the integer values but does not go and execute the next lines so it can validate the day,month, and years ranges using the if statements. Any idea's?
Are you sure it's not getting there?
Code:
#include <stdio.h>
int main(void)
{
char buff[] = "16/8/2005\n";
int date, month, year;
if ( sscanf( buff, "%d/%d/%d", &date, &month, &year ) == 3 )
{
printf("date = %d, month = %d, year = %d\n", date, month, year);
}
return 0;
}
/* my output
date = 16, month = 8, year = 2005
*/
Originally Posted by
ILoveVectors
%d i thought that was for double's?
No, %d is not for doubles -- it is for ints. For *scanf, %d specifies base 10; with %i the expected format "is the same as expected for the subject sequence of the strtol function with the value 0 for the base argument." (A double uses %lf with *scanf.)