M
mathieu
Hello,
I am trying to parse a string and I am surprised by the result(*)
When using:
sscanf(s, "%03u%c", &val, &f);
If a number less than 3 digits is found, shouldn't sscanf report
that ?
Thanks
Mathieu
(*)
#include <stdio.h>
void parse(const char *s)
{
unsigned int val;
char f;
int k = sscanf(s, "%03u%c", &val, &f);
printf( "%d %u %c\n", k, val, f);
}
int main()
{
// 21 years:
parse( "021Y" );
// -1 year (invalid)
parse( "0-1Y" );
return 0;
}
I am trying to parse a string and I am surprised by the result(*)
When using:
sscanf(s, "%03u%c", &val, &f);
If a number less than 3 digits is found, shouldn't sscanf report
that ?
Thanks
Mathieu
(*)
#include <stdio.h>
void parse(const char *s)
{
unsigned int val;
char f;
int k = sscanf(s, "%03u%c", &val, &f);
printf( "%d %u %c\n", k, val, f);
}
int main()
{
// 21 years:
parse( "021Y" );
// -1 year (invalid)
parse( "0-1Y" );
return 0;
}