I found this subset of code in the frequently asked questions section and decided to try it out. I found a couple of problems with it and was wondering if anyone can help me understand.

const char* str_int = "777";
const char* str_float = "333.3";
int i;
float f;
if(EOF == sscanf(str_int, "%d", &i)){
//error
}
if(EOF == sscanf(str_float, "%f", &f)){
//error
}

First of all, if the string value is "hello", sscanf returns 0, not EOF. So I don't understand why the author recommends checking for EOF. If the input string is not a number, then I want to take the error path.

Second, if I define the variable f to be of type double instead of float, the sscanf function will fail. Why? I thought double is a float but just twice the size. I searched in the MSDN for format specifiers and found nothing to indicate a special specifier for a double. Does anyone know what is going on here? When I say fail, I mean that the function returns 0 and the variable f will be garbage as if sscanf refuses to even try to convert the string to a double. However, it works great as long as the variable f is declared as a float.

Best Regards,

Shawn Fox