#include <stdio.h>#include <conio.h>#include <string.h>#define N 81void TestFunc();void fun(char *str,int n){/**********Begin**********/int i,j;char c;for(i=0,j=n-1;i<j;i++,j--) /*或者for(i=0,j=n-1;i<n/2;i++,j--)*/{c=*(str+i);*(str+i)=*(str+j);*(str+j)=c;} /********** End ********** }void main(){ char s [N];int l;printf("input a string:");gets(s);l=strlen(s);fun(s,l);printf("The new string is :");puts(s);TestFunc();}
C语言:将主函数中输入的字符串反序存放。例如:输入字符串“abcdefg“ 则应输出“gfedcba“。