编个倒序输出字符串。指针数组输出的问题。。。晕了。搞了一个小时还不行
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
void main()
{
char s[]="I Miss You";
char *p,*p2[5];
p=strtok(s," ");
int count=1;
int i=0;
while(p)
{
p2[i]=p;
i++;
p=strtok(NULL," ");
count++;
}
for( i=count-1;i>0;i--)
cout<<*p2[i]<<" ";
}
最后输出有问题。。。怎么修改
[解决办法]
#include<iostream>#include<iomanip>#include<string>using namespace std;void main(){ char s[]="I Miss You"; char *p,*p2[5]; p=strtok(s," "); //int count=1; int i=0; while(p) { p2[i]=p; i++; p=strtok(NULL," "); //count++; } for(int j=i-1;j>=0;j--) printf("%s ", p2[j]);}