/*
Date: 10/03/19 19:39
Description:字符串逆序
*/
#include<stdio.h> #include<string.h> void reverse(char s[]) { int i,n=strlen(s); char t; for(i=0;i<n/2;i++) { //用中间变量交换 t=s[i]; s[i]=s[n-i-1]; s[n-i-1]=t; } } int main(void) { char s[20]; printf("Enter a string: "); gets(s); reverse(s); printf("After reverse: "); puts(s); return 0; }
【运行结果】: