/**
 * Copyright (c) 2001,2002 Yoon, Hyunho <hhyoon@kldp.org>
 * http://mooo.org
 * ----------------------------------------------------------------------
 *
 * LICENSE
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
#include <stdio.h>
#include <string.h>
/* 함수 원형 */
char *str_reverse(char *str);
/* 메인 함수 시작 */
int main()
{    /* 문자열을 저장할 배열 */
    char buffer[81];
    char *rev;
    printf("Enter a String: ");
    /* gets() 함수를 이용해 문자열을 입력 받는다.
     * 이 때 반드시 배열을 이용해야 한다. */
    gets(buffer);
    /* 문자열을 뒤집어서 뒤집은 문자열을 반환한다.
     * 정확히 말해 뒤집은 문자열의 시작 주소를 반환한다. */
    rev = str_reverse(buffer);
    printf("Reversed String: %s\n", rev);
}/**
 * str_reverse()
 *
 * char *str_reverse(char *str)
 *  1. 문자열의 매개변수로 받아 문자열을 반전시킨 후 반환한다.
 *  2. 함수의 매개변수와 반환값 모두 포인터 혹은 배열이다.
 */
char *str_reverse(char *str)
{    int i, num;
    /* 함수가 리턴하더라도 이 배열에 저장된 내용을 사용하고자 ..
     * static 형으로 선언한다. */
    static char temp[81];
    /* 문자열의 길이를 구한다. */
    num = strlen(str);
    for (i = 0; i < num; i++)
        temp[i] = str[num - i - 1];
    /* 마지막에 널문자를 붙여준다.
     * 그래야만 제대로 된 문자열이 된다. */
    temp[i] = '\0';
    /**
     * 문자열의 시작 주소를 반환한다.
     * 이렇게 함수에서 값을 반환하는 경우가 아니라 주소를 반환하는 경우에는 ..
     * 반드시 static 변수로 선언해줘야 한다. 
     * 일반적으로 배열을 반환하는 경우가 이에 해당된다.
     */
    return temp;
}
이 작은숲 문서의 출처는 위키노트의 위키노트/C 언어 예제/문자열 뒤집기 문서입니다.