11、编写一个函数,试输入一个字符串安反序存放。

/*
编写一个函数,试输入一个字符串安反序存放。
 */

#include <stdio.h>
#include <stdlib.h>

void reverse(char *pStr)
{
    int strLength = 0;
    char *front = pStr;
    while(*front != '\0')
    {
        ++front ;
        ++strLength;
    }
    front = pStr;
    char *tail = pStr + strLength - 1;
    while(front <= tail)
    {
        char temp = *front;
        *front = *tail;
        *tail = temp;
        ++front;
        --tail;
    }

}

int main()
{
    char str[100];
    scanf("%s", str);
    reverse(str);
    printf("%s", str);
    return 0;
}

posted @ 2021-09-22 21:20  叶梓渔  阅读(419)  评论(0)    收藏  举报