我接受来自用户的字符串然后使用空格打印拆分字符串单词并在第二次迭代pch="*"
内将其打印在函数内部但是当它在main
内调用时它仍然具有选择。
如何在主功能中出现功能变化?
void moveNext(char * pch)
{
pch=strtok(NULL," ");
}
int main()
{
char * str;
clrscr();
printf("\n please enter sql comm.....\n");
flushall();
gets(str);
//user has enterd that string select * from std
pch = strtok(str," ");
while(pch != NULL)
{
printf("%s",pch);
moveNext(pch);
}
getch();
return 0;
}
答案 0 :(得分:0)
以下代码将帮助您摆脱函数movenext
int main()
{
char *p;
char a[20];
printf("ENter name:\n");
fgets(a,20,stdin);
p = strtok(a," ");
while( p != NULL)
{
printf("%s ",p);
p = strtok(NULL," ");
}
}