我的代码假设循环执行命令,然后执行命令,直到命令退出。当它运行时,我得到一个永无止境的循环。
void run(){
char command[100][100], *p;
int numOfArgs;
while(1){
p=&command[0][0];
numOfArgs = 0;
while(getchar()!= '\n'){
while(getchar()!= ' '){
*p=getchar();
p++; //increased to next char in string
}
*p='\0';
numOfArgs++; //increases number of strings
p=&command[numOfArgs][0]; //References p to location 0 of next string
}
if(strcmp(command[0], "/*command*/") == 0){
//Do command
}
if(strcmp(command[0], "exit") == 0)
return;
else printf("Not a valid command");
}
}