- /************************************************************************/
- /* 字符串的反转 */
- /************************************************************************/
- #include <stdio.h>
- void reverse(char a[])
- {
- int i,n;
- char t;
- n=strlen(a);
- for(i=0;i<n/2;++i)
- {
- t=a[n-i-1];
- a[n-i-1]=a[i];
- a[i]=t;
- }
- }
- int main(void)
- {
- char str[20];
- printf("Please input the string :\\n");
- gets(str);
- reverse(str);
- printf("The string after reverse is :\\n");
- puts(str);
- printf("\\n");
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/0212201411149.html
来源: http://www.codesnippet.cn/detail/0212201411149.html