c - 无限循环,我不知道为什么
问题描述
我想将两个字符串的比较用作循环的条件,但循环进入无限循环,我不知道为什么。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void input(int a[], char *comando, char *aux) {
fgets(aux, 35, stdin);
sscanf(aux, "%s %d %d", comando, &a[0], &a[1]);
}
int table_size=10;
int ar_temp[2];
char comando[2];
char aux[35];
int main() {
while((strcmp (comando, "X"))!=0 || (strcmp (comando, "x")!=0)) {
input(ar_temp, comando, aux);
}
return 0;
}
请帮帮我
解决方案
条件错误,while 语句总是被评估为真。
while((strcmp (comando, "X"))!=0 || (strcmp (comando, "x")!=0))
它应该是:
while((strcmp (comando, "X"))!=0 && (strcmp (comando, "x")!=0))
推荐阅读
- github - Github Pages 仅在某些目录中找不到 index.html
- prolog - 如何获取用户输入的每个单词的首字母
- mongodb - 我无法使用 Visual Studio Code 将 Strapi 与 MongoDB 连接起来。请协助我
- html - 如何修改里面的内容
- java - 类和子类之间的隐式和显式转换
- c - 如果一个变量是一个结构体的指针,那么通过指针变量访问结构体数据成员的操作符是什么?
- php - 替换单词并保持找到的字符串区分大小写
- sql - 如何识别两行数据的所有匹配列?
- function - 如何仅使用谷歌脚本为我的谷歌工作表创建条件格式?
- python - Selenium - 问题获取/单击按钮元素