C언어 문자열 뒤집기

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:41 판 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))

1 개요

C언어 문자열 뒤집기
#include <stdio.h>
#include <string.h>
int main() {
    char s[5] = "hello";
    int i, j, temp;
    for (i=0, j=strlen(s)-1; i<j; i++, j--) {
        temp = s[i];
        s[i] = s[j];
        s[j] = temp;
    }
    printf("%s\n", s); // olleh
}

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}