对字符串进行倒序排序

#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#define QW "quit"
char * gets(char *);
char *ar(char *p) {
char *begin = p;
char *last = p + strlen(p)-1;
while (begin < last) {
char temp = *last;
*last = *begin;
*begin = temp;
begin++;
last--;
}
return p;
}
int main(void) {
char *t;
char *w;
t = (char *)malloc(sizeof(char) * 100);
printf("输入字符串:");
while (strcmp(gets(t), QW)) {
w = ar(t);
printf("%s\n", w);
printf("输入字符串:");
}
free(t);
return 0;
}

上一篇:判断数据是否为连续数据并合并输出多少至多少


下一篇:Leetcode 58、最后一个单词的长度