在下面的代码中,我希望 sscanf 返回 0,但它返回 1 并将 0.000000 分配给浮点变量 x。当字符串以字母 i 开头但没有其他字母时,也会发生相同的行为。
void main() {
int ss_return;
float x;
char str_to_sscanf[] = "noduh";
ss_return = sscanf( str_to_sscanf, "%f", &x );
printf( "\n\nThe word passed to sscanf is %s", str_to_sscanf );
printf( "\n\nWhen looking for a float, sscanf returned %d", ss_return );
printf( "\n\nand assigned %f to x (declared as float)", x );
printf( "\n\nWHY DID sscanf NOT RETURN ZERO????" );
}
程序的输出是:“两个奇怪的字符”duh
我错过了什么?