#include <iostream.h>
#include <fstream.h>
#include <string.h>
void ReverseWord(char *ori)
{
int n=strlen(ori);
char *p=ori;
char m;
char *q=(ori+n-1);
while(p<=q)
{
m=*p;
p=q;
*q=m;
p++;
q--;
}
}
char* fun(char *ch)
{
char *p=ch;
int i=0;
char word1[10];
char word2[100];
char *q=word2;
while(*p!='/0')
{
while(*ch!=' ')
{
word1[i]=*p++;
}
ReverseWord(word1);
strcat(word2,word1);
}
return q;
}
void main()
{
char ch[100]="C++ is an Object-Oriented Programming Language";
char *q;
q=fun(ch);
ofstream ofile("OutPut.txt");
cout<<q;
ofile<<q;
}
为什么错误????
兄弟,我看你莫不是东大的?怎么和我做的题一样?我把我做的写在下面给你参考参考吧……#include<iostream.h>#include<fstream.h>#include<string.h>void ReverseWord(char *ori){ int i=0,len=strlen(ori); char *s1,*s2; s1=new char[len+1]; strcpy(s1,ori); s2=s1+len-1; for(i=0;i<len;i++) ori[i]=*s2--; delete []s1; }char *fun(char *ch){ int len=strlen(ch); char *s=new char[len+1]; char *ch1=ch,*s2=s; while(*ch1) { if(*ch1!=' ') { char ori[20]="\0"; char *s1=ori; while(*ch1!=' '&&*ch1) *s1++=*ch1++; ReverseWord(ori); for(int i=0;i<int(strlen(ori));i++) *s2++=ori[i]; *s2++=' '; } else while(*ch1==' '&&*ch1) ch1++; } s2--;*s2='\0'; return s;}void main(){ char *ch="C++ is an Object-Oriented Programming Language"; cout<<"原字符串为:"<<ch<<endl; char *nch=fun(ch); ofstream ofile("OutPut.txt",ios::out); cout<<"逆转后字符串为:"<<nch<<endl; while(*nch) ofile<<*nch++; cout<<"输出完成!"<<endl; ofile.close(); }
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息