使用scanf后,C程序停止工作

时间:2015-10-24 10:03:05

标签: c codeblocks

所以我有这个C代码

wp-content/themes/your-theme/woocommerce

但是,在我为a和b插入数字后,程序停止工作。请帮我 C noob在这里

2 个答案:

答案 0 :(得分:1)

在您的代码中,您有以下行错误:

printf(c);

因为 printf()语法就像我在下面写的那样

printf("%d",c);

所以你现在的代码是:

#include <stdio.h>

int main()
{
   int a;
   int b;
   int c;
   scanf("%d", &b);
   scanf("%d", &a);
   c= a + b;
   printf("%d",c); //this is the correct printf() syntax 
   return 0;
}

答案 1 :(得分:0)

printf(c);

应该是

printf("%d\n", c); /* `\n` at the end of the string flushes the `stdout` */

因为printf期望const char*作为其第一个参数,而不是int