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