执行代码 MSB6006 时出错 "CL.exeexecuted with code 2 [英] Error while executing code MSB6006 "CL.exeexecuted with code 2
问题描述
在 Visual Studio 2019 上执行代码时出现以下错误MSB6006"CL.exe" 以代码 2 退出
I am getting the following error while executing code on Visual Studio 2019 MSB6006"CL.exe" exited with code 2
#include<stdio.h>
#include<conio.h>
int main()
{
int a, b, c,x;
x = a / (b - c);
printf("\n Enter values of a,b and c");
scanf_s("%d%d%d", &a, &b, &c);
printf("\n The value of x is %d", x);
return 0;
}
推荐答案
您的语句顺序已关闭.
首先为 a
、b
和 c
赋值.
只有在计算中使用这些值之后.
Your order of statements is off.
First assign values to a
, b
, and c
.
Only after use those values in calculations.
#include <stdio.h>
int main(void) {
int a, b, c, x;
// x = a / (b - c); // NOPE! a, b, and c have no valid values
printf("Enter values of a, b and c\n");
scanf("%d%d%d", &a, &b, &c);
x = a / (b - c); // calculation moved here; a, b, and c (hopefully) have valid values now
printf("The value of x is %d\n", x);
return 0;
}
注意:要检查scanf()
的返回值,以确保a
、b
和c
具有有效值.
Note: the return value of scanf()
should be checked to be sure all of a
, b
, and c
have valid values.
if (scanf("%d%d%d", &a, &b, &c) != 3) /* error */;
注2:我对你的代码做了一点改动:去掉了非标准的
,改变了大部分'\n'
为了更加面向行,替换了可选的 scanf_s
(此功能可能并非在所有 C11/C18 实现中都存在).
Note 2: I changed your code a little bit: removed non-standard <conio.h>
, changed the placing of most '\n'
to be more line-oriented, replaced the optional scanf_s
(this function may not exist in all C11/C18 implementations).
这篇关于执行代码 MSB6006 时出错 "CL.exeexecuted with code 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!