简体   繁体   English

C - scanf unsigned char

[英]C - scanf unsigned char

I am trying to use scanf() for reading an unsigned char value with %hhu , but the compiler returned me: 我试图使用scanf()读取%hhu的unsigned char值,但编译器返回给我:

error: unknown conversion type character 'h' in format
 [-Werror=format]| // line 3 error: too many arguments for format
 [-Werror=format-extra-args]| // line 3 

With this following code: 使用以下代码:

printf("Enter a number: ");
unsigned char nb;
scanf("%hhu", &nb); // line 3
printf("Number: %u\n", nb);
return (nb);

A discussion on this issue can be found here . 关于这个问题的讨论可以在这里找到。 This is specific to MinGW. 这是MinGW特有的。
From this comment in the discussion the issue is identified as: 这个讨论意见的问题确定为:

This is most likely related to bug https://sourceforge.net/p/mingw-w64/bugs/652/ in that the include order and compiler driver actually screws things up with respect to C standard output and format specifiers. 这很可能与错误https://sourceforge.net/p/mingw-w64/bugs/652/有关,因为包含顺序和编译器驱动程序实际上与C标准输出和格式说明符有关。

And is proposed solution is: 并提出的解决方案是:

to always define __USE_MINGW_ANSI_STDIO so that the newer ansi format specifiers can be used and to ensure that long double (at least) is not passed between MSVC compiled and gcc compiled code. 始终定义__USE_MINGW_ANSI_STDIO,以便可以使用较新的ansi格式说明符,并确保在MSVC编译和gcc编译的代码之间不传递long double(至少)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM