#include
#include
#define N 100
void convert(char s[N])
{
int i,j;
char temp;
for(i=0; i
j=strlen(s)-1;
temp = s[i];
s[i] = s[j-i];
s[j-i] = temp;
}
printf("Now string:\n%s\n",s);
}
int main()
{
int i;
char str[N];
printf("Enter the string:\n");
gets(str);
printf("Your input string is:\n%s\n",str);
convert(str);
return 0;
}
我简单写了一个,你看是否合适。
仅供参考哈!
#include "stdio.h"
void Reverse(char *s)
{
char *p=s;
while(*p != '\0') p++;
p--;
char *q=s;
while(p>q)
{
char temp=*p;
*p=*q;
*q=temp;
q++;
p--;
}
}
main()
{
char a[6]="abcde";
Reverse(a);
printf("%s\n",a);
}