Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.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
While循环受strcmp if语句的影响。为什么会这样?_C - Fatal编程技术网

While循环受strcmp if语句的影响。为什么会这样?

While循环受strcmp if语句的影响。为什么会这样?,c,C,基本上,在我的程序中,我对下面的while循环有一些问题。以下是我遇到问题的代码部分: char *nameOfTheCommand; char *arrayArgs[500]; //track for redirection. If set, gives position of the file name. Else it equals zero int redirectionCheck=0;

基本上,在我的程序中,我对下面的while循环有一些问题。以下是我遇到问题的代码部分:

            char *nameOfTheCommand;
            char *arrayArgs[500];
            //track for redirection. If set, gives position of the file name. Else it equals zero
            int redirectionCheck=0;
            arrayArgs[0]=token;
            int i;
            i=0;
            //While still arguements to take in, do this
            while(arrayArgs[i]!=NULL)
            {
                i++;
                arrayArgs[i]=strtok(NULL, " \n");
                if(strcmp(arrayArgs[i], "<")==0)
                {
                     redirectionCheck=i;
                }
            }
char*命令名;
char*arrayArgs[500];
//跟踪重定向。如果设置,则给出文件名的位置。否则等于零
int redirectionCheck=0;
arrayArgs[0]=令牌;
int i;
i=0;
//当仍有争论需要接受时,请这样做
while(arrayArgs[i]!=NULL)
{
i++;
arrayArgs[i]=strtok(空,“\n”);

如果(strcmp(arrayArgs[i],“在循环的最后一次迭代中,您将
NULL
传递给
strcmp
。这可以通过重新排列循环来避免:

i = 1;
// read subsequent tokens
while((arrayArgs[i] = strtok(NULL, " \n")) != NULL)
{
    if(strcmp(arrayArgs[i], "<") == 0)
    {
         redirectionCheck = i;
    }
    i++;
}
i=1;
//读取后续标记
而((arrayArgs[i]=strtok(NULL,“\n”)!=NULL)
{

if(strcmp(arrayArgs[i],“在调试器中跟踪它?当strtok失败并将空指针传递给strcmp时会发生什么情况?”不应该
if(strcmp(arrayArgs[i],“否,因为arrayArgs[0]预先设置为令牌。我正在设置arrayArgs[1]及更高版本,并有意跳过arrayArgs[0]@RetiredInja,我尝试过gdb,但诚实地遵循它时遇到了困难,尤其是在子进程方面。