Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 也许是我写错了病毒?_C_Windows - Fatal编程技术网

C 也许是我写错了病毒?

C 也许是我写错了病毒?,c,windows,C,Windows,当我运行下面的代码时,它一直工作到简单游戏的3次迭代,但在第3次迭代之后,CPU使用率上升到90%,并立即崩溃。即使控制台也被终止,但在windows任务列表中可以看到下面的程序exe。我必须手动删除它,windows CPU才能恢复到3%的水平。 你知道这是什么原因吗?(我在Windows7 64位机器上使用Dev-C++) #包括 #包括 #包括 无效游戏(void); 内部主(空){ srand(时间(空)); 游戏(); 返回0; } 无效游戏(无效){ int-choice=1; wh

当我运行下面的代码时,它一直工作到简单游戏的3次迭代,但在第3次迭代之后,CPU使用率上升到90%,并立即崩溃。即使控制台也被终止,但在windows任务列表中可以看到下面的程序exe。我必须手动删除它,windows CPU才能恢复到3%的水平。 你知道这是什么原因吗?(我在Windows7 64位机器上使用Dev-C++)

#包括
#包括
#包括
无效游戏(void);
内部主(空){
srand(时间(空));
游戏();
返回0;
}
无效游戏(无效){
int-choice=1;
while(选项!=0){
int number1,number2,resultStudent,result;
number1=1+rand()%9;
number2=1+rand()%9;
结果=数字1*数字2;
printf(“多少是%d乘以%d?”,数字1,数字2);
scanf(“%d”和&resultStudent);
while(resultStudent!=结果){
printf(“否,请再试一次。”);
scanf(“%d”和&resultStudent);
}
printf(“非常好”\n);
printf(“您想再次播放吗?(0表示退出):”;
scanf(“%d”,选择(&C);
printf(“嗯,你想再玩一次…\n”);
}
printf(“程序终止”);
}

Pedantic:这不是一个真正的答案:如果您(有意或无意)输入“y”或“是”作为您是否要继续的问题的答案,程序将尝试以数字的形式一次又一次地在循环中读取该文本,这可能会导致高cpu负载,或导致其运行的窗口关闭。不是病毒。我认为这个问题不值得所有的否决票。它当然不是病毒,但它是一个中等有趣的bug。(不断地检查scanf返回的值将是一个很好的捕获方法。)事实上,我的+1是因为尽管标题对it高手来说可能有点滑稽,但OP根本不理解这种行为,而且显然对大量意外症状感到有点恐慌。事实上,我对此表示赞赏:他注意到了CPU负载、控制台关闭等。学习时首先需要注意的是。我喜欢一种病毒的想法,它会提示你回答简单的数学问题。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void game(void);
int main(void) {
    srand(time(NULL));
    game();
    return 0;
}
void game(void) {
    int choice = 1;
    while (choice != 0) {
        int number1, number2, resultStudent, result;
        number1 = 1 + rand() % 9;
        number2 = 1 + rand() % 9;
        result = number1 * number2;
        printf("How much is %d times %d ?", number1, number2);
        scanf("%d", & resultStudent);
        while (resultStudent != result) {
            printf("No. Please try again.");
            scanf("%d", &resultStudent);
        }
        printf("Very Good\n");
        printf("Do you wanna play again?(0 for Exit):  ");
        scanf(" %d", &choice);
        printf("Hmm you wanna play again...\n");
    }
    printf("Program is terminated.");
}