读书人

代码有异常吗

发布时间: 2012-07-16 15:45:00 作者: rapoo

代码有错误吗?
#include<iostream>
using namespace std;
int main()
{
char s[]=
"what is your name",
*ps=s;
do

cout<<nextword(&ps)<<endl;

while (*ps);
return 0;
}
char *nextword(char **pp)
{
static char word[81];
while(**pp==' ')(*pp)++;
char *pw=word;
while(**pp && **p!=' ')
*pw++=*(*pp)++;
*pw='\0';
return word;
}

[解决办法]
#include<iostream>
using namespace std;

char *nextword(char **pp)
{
static char word[81];
while(**pp==' ')(*pp)++;
char *pw=word;
while(**pp && **pp!=' ')
*pw++=*(*pp)++;
*pw='\0';
return word;
}

int main()
{
char s[]="what is your name";
char *ps=s;

do{
cout<<nextword(&ps)<<endl;
}while (*ps);

return 0;
}
你把上面的代码拷过去试试~出错的原因你自己看看吧~

读书人网 >C++

热点推荐