C : Arduino : Check to see if all the values in an array are larger than x and set them to zero

标签 c arrays arduino

我想做的是:如果存储在数组元素中的任何值大于 2,则将数组中该元素的值设置为零

int  column[] = { 0-var1, 1-var3, 2-var2, 3-var6, 4-var7 };

if (column[] > 2){
    column[] = 0;
}

但显然它无法运行代码,因为我没有指定哪个索引,但这是我不希望它只检查一个元素的要点,我希望它检查整个数组

最佳答案

您需要将 if 语句放在带有索引的循环中。

for(x=0; x < sizeof(column) / sizeof(int); x++) {
  if (column[x] > 2) {
      column[x] = 0;
  }
}

关于C : Arduino : Check to see if all the values in an array are larger than x and set them to zero,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22520084/

相关文章:

c - gcc 错误 –Wl,-rpath,./ffmpeg/lib : No such file or directory

javascript - 在 JavaScript 中标记化

linux - 在 Ubuntu Linux 上为 Arduino 编译程序——还有其他方法吗?

c - 如何获取变量输入并将其附加到另一个变量?

php - 按给定索引对多维数组进行排序 - PHP?

arduino - 从 SD 卡运行 arduino sketch

c - 除法结果始终为零

c - 我可以选择禁用这两个 MISRA 规则 : one statement per function and mandatory function prototypes?

调用 rename() 而不覆盖意外数据且不覆盖意外数据

c - 结构处理和结构数组