什么是格式说明无符号短整型? [英] What is the format specifier for unsigned short int?
问题描述
我有以下程序
的#include<&stdio.h中GT;INT主要(无效)
{
无符号短整型长度= 10; 的printf(请输入长:);
scanf函数(%U,&安培;长度); 的printf(值%U \\ n,长度); 返回0;
}
,当使用编译 GCC FILENAME.C
发表了如下警告(在 scanf()的
线)。
警告:格式'%U'型预计的说法无符号整型*',但参数2的类型短无符号整数*'[-Wformat]
然后我提到的 C99规范 - 7.19.6格式化输入/输出功能
,并使用长度修改(比如当无法理解正确的格式说明短
,长
等)与无符号
为 INT
数据类型。
是%U
正确的说明无符号的短整型
?如果是这样,为什么我收到上述警告?
编辑:
大多数时候,我试图%呃
键,它仍然给予警告。
尝试使用%H
修改
scanf函数(%虎,&安培;长度);
^
指定后续的D,I,O,U,X,X,或n转换
说明适用于参数类型的指针或短
无符号短
块引用>I have the following program
#include <stdio.h> int main(void) { unsigned short int length = 10; printf("Enter length : "); scanf("%u", &length); printf("value is %u \n", length); return 0; }
Which when compiled using
gcc filename.c
issued the following warning (in thescanf()
line).
warning: format ‘%u’ expects argument of type ‘unsigned int *’, but argument 2 has type ‘short unsigned int *’ [-Wformat]
I then referred the
C99 specification - 7.19.6 Formatted input/output functions
and couldn't understand the correct format specifier when using the length modifiers (likeshort
,long
, etc) withunsigned
forint
data type.Is
%u
the correct specifierunsigned short int
? If so why am I getting the above mentioned warning?!EDIT: Most of the time, I was trying
%uh
and it was still giving the warning.解决方案Try using the
"%h"
modifier:scanf("%hu", &length); ^
Specifies that a following d , i , o , u , x , X , or n conversion specifier applies to an argument with type pointer to short or unsigned short.
这篇关于什么是格式说明无符号短整型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!