c - 代码在输出 C 处无法正常工作
问题描述
我试图从键盘读取 2 个变量并将它们写在屏幕上,但我遇到了问题,程序只显示一个..
#include <stdio.h>
#include <stdlib.h>
int main()
{
short int n,x;
scanf("%d",&n);
scanf("%d",&x);
printf("%d %d",n,x);
return 0;
}
我介绍了 14 和 15,程序返回我 0 和 15 有人能告诉我为什么吗?
解决方案
对 short int 使用 %hd 格式说明符 对 unsigned int 使用 %hu 格式说明符 对 int 使用 %d 格式说明符 对 long int 使用 %ld 格式说明符
#include <stdio.h>
#include <stdlib.h>
int main() {
short int n, x;
scanf("%hd", &n); // Notice %hd instead of %d for short int
scanf("%hd", &x); // Notice %hd instead of %d for short int
printf("%hd%hd", n, x);// Notice %hd instead of %d for short int
return 0;
}
推荐阅读
- azure - Azure 应用服务停止工作一段时间
- vector - 如何将 .kmz 文件转换为 .zip?
- firebase - 在 Flutter 中使用 Firebase 身份验证检查用户是否是新用户
- c# - SMTP:邮箱不可用。服务器响应是:Error458 块
- javascript - 我们如何在 ES7 中调用类内部的方法?
- windows - SSL 和 Umbraco
- google-tag-manager - 我正在使用自定义图像标签在我的网站上放置一个“图像像素标签”。我希望标签在页面顶部触发
- python - Python 3 urllib + PySocks - 使用 SOCKS4 代理打开 url 失败
- swift - 使用 enumerateBodies 沿RayStart 反弹光线
- android - Google Play 开发者 API | 检索评论