C-while(*表[i])的意思是什么?
我需要向数组中添加一个字符串,并需要一些帮助来了解这意味着什么。以下是我所拥有的:C-while(*表[i])的意思是什么?,c,arrays,string,while-loop,C,Arrays,String,While Loop,我需要向数组中添加一个字符串,并需要一些帮助来了解这意味着什么。以下是我所拥有的: #include <stdio.h> #include <stdlib.h> int insert(char *word, char *Table[], int n) { //*word is the string to be added, *Table[] is the array, n is //the return value, which is the number of word
#include <stdio.h>
#include <stdlib.h>
int insert(char *word, char *Table[], int n)
{
//*word is the string to be added, *Table[] is the array, n is
//the return value, which is the number of words in the array after adding *word
int i = 0;
while(*Table[i])
{
if strcmp(*Table[i], *word) == 0)
{
return n;
break;
}
}
}
#包括
#包括
int insert(字符*字,字符*表[],int n)
{
//*word是要添加的字符串,*Table[]是数组,n是
//返回值,即添加*word后数组中的字数
int i=0;
而(*表[i])
{
如果strcmp(*表[i],*字)==0)
{
返回n;
打破
}
}
}
我不久前写过这篇文章,现在正在重温它。我不知道while*表[I]是什么意思,因此我不知道下面的代码是什么意思。此外,此代码不完整,因此不要麻烦告诉我它不会添加字符串。运算符*取消引用指针,[i]也取消引用指针 由于Table被声明为char*Table[],这与char**相同,因为它是指向指针类型的指针(类似于二维数组) 在本例中,从用法中可以明显看出,表是字符串数组(字符串是字符数组(因此是数组类型的数组)) 所以表[i]是一个指向字符串数组中第i个字符串的指针,然后*再次取消引用。作者在这里所做的是寻找字符串数组后面的NULL(零),这显然是确定数组结尾的方法