#include"shell.h"
int main()
{
char cInput[50];
char cCopy[50];
char *pCommand;
char pArguement[10];
bool bRun = true;
while(strcmp(pCommand, "exit"))//run untill exit
{
printf("[myshell]%% ");
cin >> cInput; //get command from user
for(int i=0; i<50; i++)
cCopy[i] = cInput[i];
//get command
pCommand = strtok(cInput, " ");
if(!strcmp(pCommand, "pwd"))
{
printf("No FUNCTIONAILITY FOR PWD! \n");
}
else if(!strcmp(pCommand, "list"))
{
printf("No FUNCTIONAILITY FOR LIST! \n");
}
else if(!strcmp(pCommand, "history"))
{
printf("No FUNCTIONAILITY FOR HISTORY! \n");
}
else if(!strcmp(pCommand, "prompt"))
{
// pCommand = strtok(cCopy, "y");
while(pCommand != NULL)
{
printf(" %s \n", pCommand);
pCommand = strtok(NULL, " ");
}
return 0;
}
else//command not found
{
printf("%s: Command not found \n", pCommand);
}
}
return 0;
}
所以我试图遵循C标准库中的strtok示例,但我无法弄清楚为什么我无法从cstring cInput获取下一个单词。我的印象是使用:
while(pCommand != NULL)
{
printf(" %s \n", pCommand);
pCommand = strtok(NULL, " ");
}
会导致获得下一个单词。
有任何帮助吗? 谢谢!