C中char*[]的范围是什么?

fin*_*oop 2 c scope strcat

我有一些代码执行以下操作:

while(some condition)
{
     char *line[WORDLEN];
     //do stuff to line, including strcat(line, "words")
     printf("%s", line);
     line[0] = '\0';
}
Run Code Online (Sandbox Code Playgroud)

然而,似乎line [0] ='\ 0'没有做我希望它会做的事情.我想回到循环中,并使用line,就像它刚刚声明一样.循环第一次按需运行,但是在后续迭代中无法将行视为新的char*[].知道为什么?

pax*_*blo 6

char *line[WORDLEN];
Run Code Online (Sandbox Code Playgroud)

是一个字符指针数组.我想你的意思是:

char line[WORDLEN];
Run Code Online (Sandbox Code Playgroud)

单个字符数组.我只想选择:

while(some condition)
{
     char line[WORDLEN];
     line[0] = '\0';
     //do stuff to line, including strcat(line, "words")
     printf("%s", line);
}
Run Code Online (Sandbox Code Playgroud)

因为这样可以保证在开始对循环做任何事情之前,每次循环时字符串都是空的,而不管范围规则如何.