c++简单程序出错在哪里?谢谢

来源:百度知道 编辑:UC知道 时间:2024/05/17 18:06:35
简单实现输入字符串倒序输出...为什么第一个字符没变.谢谢了
#include <iostream>
#include <string.h>
#include <math.h>
using namespace std;
int main()
{
int a=0,b=0,i=0;
char str[10];
cout<<"shuru:"<<endl;
cin>>str;
cout<<endl;
char *p,*q,*j;
p=q=j=str;

for(;*q!='\0';)
q++;
cout<<*q<<endl;
while(p<q)
{*j=*p;
*p=*q;
*q=*j;
p++;
q--;
}
cout<<str<<endl;
return 0;
}

用我的吧,你的太麻烦了,没必要.
#include<stdio.h>
#include<string.h>
int main()
{
int n,t;char a[201];
gets(a);
t=strlen(a);
for(int j=0;j<t;j++)
printf("%c",a[t-j-1]);
printf("\n");
return 0;
}