Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.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 - Fatal编程技术网

如何使用整数数组作为C中字符数组的索引?

如何使用整数数组作为C中字符数组的索引?,c,C,因此,我试图将计算得到的位置存储到整数数组中,然后使用这些位置(整数数组的元素)作为字符数组的位置进行某种比较 以下是示例代码: int arrayposition[10]; char arrayword[10]; char string[10]; ... . . // I want to do a strcmp to compare string and arrayword //suppose for (int i = 0;;) { if (strcmp(arrayword[i], s

因此,我试图将计算得到的位置存储到整数数组中,然后使用这些位置(整数数组的元素)作为字符数组的位置进行某种比较

以下是示例代码:

int arrayposition[10];
char arrayword[10];
char string[10];
...
.
.
// I want to do a strcmp to compare string and arrayword
//suppose
for (int i = 0;;) {
    if (strcmp(arrayword[i], string[arrayposition])) {     //Obviously this is not possible( array within an 
                                                     // array)
       //do something
    }
}
使用
arrayposition
作为字符串索引的最佳方法是什么。
例如:
arrayposition[2]={1,3,5}

这可能是答案:

const char *arrayword[10] = { "word1", "word2", ... };

    if(strncmp(arrayword[i], string + arrayposition, strlen[arrayword + i]))

这会将arrayword+i中的整个字符串与从arrayposition开始的字符串进行比较。

字符串为char*类型,arrayposition为int*类型。我们如何对这两个函数执行二进制操作?@technextgen:arrayposition应该是int类型,或者缺少循环,应该是
arryposition[j]