首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

编个倒序输出字符串。指针数组输出的有关问题。晕了。搞了一个小时还不行

2012-06-29 
编个倒序输出字符串。指针数组输出的问题。。。晕了。搞了一个小时还不行#includeiostream#includeiomanip#

编个倒序输出字符串。指针数组输出的问题。。。晕了。搞了一个小时还不行
#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]<<" ";
}
最后输出有问题。。。怎么修改

[解决办法]

C/C++ code
#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]);} 

热点排行