请高手给修改C++程序(关于把字符串颠倒的)

来源:百度知道 编辑:UC知道 时间:2024/07/01 07:07:30
#include<iostream>
#include<cstring>
using namespace std;
void reverse(char*s)
{char*p,*q,temp;
p=s;
q=s+strlen(s)-1;
while(p<q){
temp=*p;
*p=*q;
*q=temp;
p++;q--;
}
}

你编得很好啊 我运行了一下 没有问题
#include<iostream>
#include<cstring>
using namespace std;
void reverse(char *s)
{char*p,*q,temp;
p=s;
q=s+strlen(s)-1;
while(p<q){
temp=*p;
*p=*q;
*q=temp;
p++;q--;
}
}
int main(){
char test[]="this is a test";
reverse(test);
cout<<test;
system("Pause");
return 0;
}

用C改写的字符颠倒
#include<stdio.h>
char temp;
void sw(char *p,char *q)
{
temp=*p;
*p=*q;
*q=temp;
}

void reverse(char*s)
{char*p,*q;
p=s;
q=s+strlen(s)-1;
while(p<q){
sw(p,q);
p++;q--;
}
printf("%s",s);
}
void main()
{
char *s;
printf("please input a string:\n");
scanf("%s",s);
getchar();
reverse(s);
getch();

}

有什么问题吗?