程序:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int fun(char *w)
{
char t, *s1,*s2;
int n = strlen(w);
s1 = w;
s2 = w+n-1;
while(s1<s2)
{
t = *s1;
*s1 = *s2;
*s2 = t;
s1++;
s2--;
}
}
int main()
{
char w[] = "hello adams";
printf("%s \n",w);
fun(w);
printf("%s \n",w);
}
运行结果:
root@ubuntu:/home/adams/c# ./2
hello adams
smada olleh
root@ubuntu:/home/adams/c#