什么是格式说明无符号短整型? [英] What is the format specifier for unsigned short int?

查看:536
本文介绍了什么是格式说明无符号短整型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下程序

 的#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 the scanf() 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 (like short, long, etc) with unsigned for int data type.

Is %u the correct specifier unsigned 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆