华为OJ平台试题 —— 数组:字符串反转

来源:互联网 发布:python 替换 16进制 编辑:程序博客网 时间:2024/05/18 16:17

字符串反转



代码:

/* * 接受一个字符串,然后输出该字符串反转后的字符串。 */#include <stdio.h>#include <string.h>/* *字符串反转函数 */char *revstr(char *str, int len){    char    *start = str;    char    *end = str + len - 1;    char    ch;    if (str != NULL)    {        while (start < end)        {            ch = *start;            *start++ = *end;            *end-- = ch;        }    }    return str;}int main(void){ char str[10000];//这里需要把数组定义大一点,要不然OJ上答案总是错误 int n;         gets(str); n = strlen(str); revstr(str,n); puts(str);}


0 0
原创粉丝点击