我正在准备一个测验,我怀疑我可能会负责实现这样的功能.基本上,给定一个网络符号的IP地址,我们如何从一个32位整数到它的点分十进制表示法(如155.247.182.83)...?显然我们也不能使用任何类型的inet函数......我很难过!
简单的问题:scanf可以读取/接受"小整数"到ANSI C中的unsigned char吗?
示例代码un_char.c:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
unsigned char character;
scanf("%hhu", &character);
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
编译为:
$ gcc -Wall -ansi -pedantic -o un_char un_char.c
un_char.c: In function ‘main’:
un_char.c:8: warning: ISO C90 does not support the ‘hh’ gnu_scanf length modifier
Run Code Online (Sandbox Code Playgroud)
hhISO C90不支持.那么在这种情况下可以使用什么scanf转换?
嗨,我现在正在学习C语言,并且练习我读过的书时遇到了一些问题.我的代码是这样的:
#include<stdio.h>
int main()
{
unsigned char one=0;
unsigned char two=0;
printf("Quantity 1 = ");
scanf("%d",&one);
printf("Quantity 2 = ");
scanf("%d",&two);
printf("The value is %d",one);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么当我试图看到one初始值的值出现而不是后面的值scanf?