c - why doesn't this program in C language print anything?
问题描述
why doesn't this program print anything?
int main(){
int a = getchar()-'0';
getchar();
int b = getchar()-'0';
int vsota = 0;
vs = (a+b)%10;
putchar(vs);
printf("\n");
}
I put in the numbers 7 and 9 and it was supossed to outprint 6 but it does not.
解决方案
putchar(vs);
writes the character whose code is the value in vs
. The value in vs
is 6. So it writes the character with code 6. That character is not the digit “6”. You do not see anything because it is a “control character” with no visible appearance. To write the character for the digit whose value is in vs
, use putchar('0' + vs);
.
Also, fix this:
int vsota = 0;
vs = (a+b)%10;
That would not have compiled, so presumably you made a mistake when entering code into Stack Overflow. Use the same name in both places.
推荐阅读
- python - shell如何获取python设置的环境变量
- tfs - 工作项类型 (WIT) 状态之间的自动转换
- python - 我不明白 python 文档中的符号
- javascript - 如何使用 java 脚本应用 css
- java - 如何在springboot中调用另一个REST API使用RestTemplate上传文件
- c - 使用 scanf 将 digit 的数值赋给 char
- c++ - 多客户端 TCP 服务器 C++ 问题
- api - 如何使用 NuSOAP 工具包在 SOAP 请求中设置请求标头
- c# - 在 hololens 中从我们的应用程序启动应用程序
- linux - 从 Nginx 版本信息中提取某些行