我的代码工作得很好。但是,当我尝试调试它时,因为这是我第一次使用 Luna Eclipse,并且想了解调试过程是如何工作的,它给了我一个错误,说
*stopped,reason="end-stepping-range",frame={addr="0x00401479",func="main",args=[],file="..\src\Assignment1A.c",fullname="C:\Users\Sunghee\workspace2\Assignment1A\src\Assignment1A.c",line="37"},thread-id="1",stopped-threads="all"
我不明白这一点,因为当我运行它时它工作得很好。错误出现在我的第一个 if 语句处
printf("\n%d + %d =%d", num1, num2, ans);
if (num2 > 0) {
printf("\n%d / %d = %d", num1, num2, num1 / num2);
printf("\n%d %% %d = %d", num1, num2, num1 % num2);
}
else {
printf("\n%d /%d is not allowed", num1, num2);
}
谁能告诉我为什么?我已经研究过它,但所有我不理解的术语...对我不起作用:p 谢谢!
当我运行它时,它可以在 Eclipse 中运行。当我逐行调试它时,错误发生在上述一行之后。 完整代码:
包括
包括
int main() { 整数 num1;//用户输入的第一个数字 整数 num2;//用户输入的第二个数字 整数答;//存储数学结果的变量
setbuf(stdout, 0);
printf("Please enter the first integer:\n");
scanf("%d", &num1);
printf("Please enter the second integer:\n");
scanf("%d", &num2);
ans = num1 + num2;
printf("\n%d + %d =%d", num1, num2, ans);
if (num2 > 0) {
printf("\n%d / %d = %d", num1, num2, num1 / num2);
printf("\n%d %% %d = %d", num1, num2, num1 % num2);
}
else {
printf("\n%d /%d is not allowed", num1, num2);
printf("\n%d %% %d is not allowed", num1, num2);
}
printf("\nThe average of %d and %d is %d", num1, num2, (num1+num2)/2);
return 0;
}
所以如果有人可以帮忙,请帮忙!正如我所说,我运行时没有问题。但我想知道为什么我调试的时候会出现错误。出于好奇:D
最佳答案
下面的代码对我来说工作得很好。我认为这与你初始化变量的方式有关。如果可能的话,请您分享整个代码。
#include <stdio.h>
int main(void) {
int num1 = 1,num2 =2,num3 = 3,ans =0;
printf("\n%d + %d =%d", num1, num2, ans);
if (num2 > 0) {
printf("\n%d / %d = %d", num1, num2, num1 / num2);
printf("\n%d %% %d = %d", num1, num2, num1 % num2);
}
else {
printf("\n%d /%d is not allowed", num1, num2);
}
return 0;
}
结果
1 + 2 =0
1 / 2 = 0
1 % 2 = 1
关于c - 代码中没有错误,但是当您调试时,我收到错误(Eclipse Luna),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31634509/