Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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_Function_Multidimensional Array_Arduino_Self Reference - Fatal编程技术网

C 如何根据传递给函数的指令对函数中的给定变量进行操作?

C 如何根据传递给函数的指令对函数中的给定变量进行操作?,c,function,multidimensional-array,arduino,self-reference,C,Function,Multidimensional Array,Arduino,Self Reference,使用C(使用Arduino/Teensy),我能够以行或列格式从网格中读取字符 我对row和col的函数调用是分开的,因为我还不能根据给出的指令在同一个函数中修改row或col 从findWordByRow()(反之亦然)内部调用findWordByCol()似乎很好,也很容易,但我觉得我在用函数findWordOnRow()和findWordOnCol()浪费代码 编辑:新示例 在这个小示例中,我尝试在多个点上解引用(*)和(&)运算器的地址。但是我无法让Seril.println输出变量行中

使用C(使用Arduino/Teensy),我能够以行或列格式从网格中读取字符

我对row和col的函数调用是分开的,因为我还不能根据给出的指令在同一个函数中修改row或col

findWordByRow()
(反之亦然)内部调用
findWordByCol()
似乎很好,也很容易,但我觉得我在用函数
findWordOnRow()
findWordOnCol()
浪费代码

编辑:新示例

在这个小示例中,我尝试在多个点上解引用(*)和(&)运算器的地址。但是我无法让Seril.println输出变量
行中包含的内容,因为它是从
字符单词[][6]={“行”,“列”}中选择的单词

如果我调用单个函数时使用以下命令,我如何执行操作:

void findWord(basedOnRow) {};  // Should modify grid[**ROW**][col]
void findWord(basedOnCol) {};  // Should modify grid[row][**COL**]
当前操作的示例。 首次通话:

// Find out where the second tile is relative to the first tile to set vector
if (vector == 0) {
                    findWordOnRow(workingWords, workingWord, stateHolder, row, col, tileCommsData.playerNumber);
} else if (vector == 1){
                    findWordOnCol(workingWords, workingWord, stateHolder, row, col, tileCommsData.playerNumber);
} else {
                    Serial.println("Something is wrong: No vector on this tile.");
}
void findWordOnRow(*指针、对象){
//做事
如果((gameGrid[row-1][col].designation!='\0'| | gameGrid[row+1][col].designation!='\0')&&(row>=0&&row
void findWordOnCol(*指针、对象){
//做事
如果((gameGrid[row][col-1]。名称!='\0'| | gameGrid[row][col+1]。名称!='\0')&&(col>=0&&col
我曾经考虑过宏——尽管我无法改变主意如何根据输入将###变成一行或###变成一列


编辑:添加语言和示例。感谢JonRSharpe指出我可以如何帮助你。

你到底尝试了什么?哪种语言?您是否有
string.h
中的函数可用于
findWordOnRow
,如果这样,在每一行上循环并使用
strstr
检查将使事情变得更简单。对于“both”函数,传递一个用于调用其中一个的标志是可以的。您可能还希望向数组传递一个点,该数组可以用“已找到”一词填充,如果未找到,则将第一个字符设置为
'\0'
,并返回指向数组(或分配的块)的指针以指示成功/失败。不要在简单函数调用就可以的地方使用宏。即使是在Arduino冒险也不值得这么做,如果有的话。谢谢大卫。我将调查strstr。我目前正在对指向的单词和strncat后面的字符串进行memcmp,这对于整个单词来说已经足够好了,但是在这个应用程序中,部分单词可能也很有用。至于指向数组的指针。我确实在一个版本中进行了这个测试,该版本在程序中进行了完全的沙盒测试。但现在我已经开始添加网络组件并更改软件的结构,我发现了更多的挑战:)再次感谢您的输入。
char-to-alter=&words[0]正在将指针转换为字符。您的意思是
char*toAlter=words[0]
?@KamilCuk,这确实会返回单词“row”。如何将返回的单词转换为变量名“row”,以便在执行
Serial.println(toAlter)
时得到“您选择了行”的结果?非常感谢。
// Find out where the second tile is relative to the first tile to set vector
if (vector == 0) {
                    findWordOnRow(workingWords, workingWord, stateHolder, row, col, tileCommsData.playerNumber);
} else if (vector == 1){
                    findWordOnCol(workingWords, workingWord, stateHolder, row, col, tileCommsData.playerNumber);
} else {
                    Serial.println("Something is wrong: No vector on this tile.");
}
void findWordOnRow (*pointers, things){

// Do things

  if ((gameGrid[row-1][col].designation != '\0' || gameGrid[row+1][col].designation != '\0') && (row >= 0 && row < GRID_Y)){                
    if (findWordOnCol(workingWords, workingWord, tileState, row, col, player) == 0) {
            allWordsComplete = 1;
        } else {
            allWordsComplete = 0;
        }
    }
}
void findWordOnCol (*pointers, things){

// Do things

  if ((gameGrid[row][col-1].designation != '\0' || gameGrid[row][col+1].designation != '\0') && (col >= 0 && col < GRID_X)){            
    if (findWordOnCol(workingWords, workingWord, tileState, row, col, player) == 0) {
            allWordsComplete = 1;
        } else {
            allWordsComplete = 0;
        }
    }
}