c - printf 程序结束后不执行其余代码? C

标签 c

在 printf 行程序自行结束后,但我不明白为什么。

#include<stdio.h>

int main ()
{
    int Sum,multiply,divide,difference,num1,num2;
    char i;
    scanf("%d", &s1);
    scanf("%d", &s2);
    printf("Type initial of your operation : ");
    scanf("%c", &i);

    return 0 ;
}

最佳答案

您无法编译它,因为 s1s2 是 undefined variable 。

因此,有关您运行它时发生的情况的任何信息都是没有意义的,因为您无法运行它。

你的意思是:

if(scanf("%d %d", &num1, &num2) == 2)
{
  printf("Operands are %d and %d, now type initial of desired operation:\n");
  if(scanf("%c", &i) == 1)
  {
  }
}

在依赖返回值之前检查 scanf() 是否成功非常重要。

关于c - printf 程序结束后不执行其余代码? C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21597756/

相关文章:

c# - 使用c#从另一个进程调用一个函数

c - 是否可以将 perror() 产生的消息发送到/var/log/syslog?

c - 帮助理解typedef结构

c - argv 和波兰语符号计算器

c - 从 strtok 向其传递字符串数组后,execvp 返回错误 "No such file or directory"

c - Linux 上的 RPC 多线程服务器 - Pthreads

c++ - 在 C 中将 Windows 控制台大小调整为全屏

计算 C 中的特定字符?

c - 带有 switch 语句的 while 循环不退出

python - 如何将此 NetHack 函数移植到 Python?