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;
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM