_int8数据类型的格式说明符是什么?
我正在使用"%hd“,但它给了我一个关于堆栈损坏的错误。谢谢:)
这是代码的一小段:
signed _int8 answer;
printf("----Technology Quiz----\n\n");
printf("The IPad came out in which year?\n");
printf("Year: ");
scanf("%hd", &answer);
printf("\n\n");
printf("The answer you provided was: %hd\n\n", answer);
发布于 2012-10-25 00:23:25
要在printf
和scanf
格式的字符串中使用C99中可移植的“显式宽度”typedefs (如int8_t
和uint_fast16_t
),您需要#include <inttypes.h>
,然后使用字符串宏PRIi8
和PRIuFAST16
,如下所示:
#include <stdint.h> // for the typedefs (redundant, actually)
#include <inttypes.h> // for the macros
int8_t a = 1;
uint_fast16_t b = 2;
printf("A = %" PRIi8 ", B = %" PRIuFAST16 "\n", a, b);
完整列表请参见the manual,并与中的typedefs交叉引用。
发布于 2012-10-24 23:57:09
man scanf:%hhd
"...但下一个指针是指向有符号字符或无符号字符的指针“。在您要在其上执行scanf
的任何系统中,_int8
等同于signed char
。
signed _int8 answer;
scanf("%hhd", &answer);
printf("You entered %d\n\n", answer);
发布于 2012-10-24 23:59:06
%hd会让你得到一个“短整数”,通常是16位,而不是想象中的8位。如果%hhd不受支持,您可能没有好的方法来执行此操作,而不是将其作为短文扫描并进行分配。
https://stackoverflow.com/questions/13052880
复制相似问题