我在执行下面提到的代码时遇到问题。我在使用 int8_t
时遇到错误,但在使用 int16_t
时却没有。我在使用 int8_t
时遇到的错误是:
12 19 [Error] expected ')' before 'SCNd8'
16 19 [Error] expected ')' before 'SCNd8'
谁能帮我解决这个问题?
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <inttypes.h>
int main()
{
int8_t N,D,quotient,remainder;
D=0;
printf("enter the Numerator between 0-255: \n");
scanf("%hhd" SCNd8 ,&N);
printf("enter the Denominator between 1-255: \n");
do{
scanf("%hhd"SCNd8 ,&D);
if (D==0)
{
printf("denominator cant be 0 \n");
printf("enter the Denominator between 1-255: \n");
}
}while(D==0);
quotient=N/D;
remainder=N%D;
printf("The quotient is %"PRId8"\n",quotient);
printf("The remainder is %"PRId8"\n",remainder);
最佳答案
改变
scanf("%hhd" SCNd8 ,&N);
到
scanf("%" SCNd8 ,&N);
这是因为 SCNd8 通常被定义为
#define SCNd8 "hhd"
所以,你不需要自己添加hhd
关于C-int8_t 不会工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41775996/