반응형

문자열 선언

#include <stdio.h>

int main() {
    char text[] = "Hello, World!";
    printf("%s\n", text);

    return 0;
}

문자열 길이

#include <stdio.h>
#include <string.h>

int main() {
    char text[] = "Hello, World!";

    int length = strlen(text);

    printf("%d\n", length);

    return 0;
}

문자열 복사

#include <stdio.h>
#include <string.h>

int main() {
    char text1[] = "Hello";
    char text2[100];

    strcpy(text2, text1);

    printf("%s\n", text2);

    return 0;
}

문자열 합치기

#include <stdio.h>
#include <string.h>

int main() {
    char text1[100] = "Hello";
    char text2[] = "World";

    strcat(text1, text2);

    printf("%s\n", text1);

    return 0;
}

문자열 비교

#include <stdio.h>
#include <string.h>

int main() {
    char text1[] = "sample";
    char text2[] = "sample";

    int compare = strcmp(text1, text2);

    printf("%d\n", compare);

    return 0;
}
반응형

'Development > C, C++' 카테고리의 다른 글

[C] 상수  (0) 2019.04.04
[C] 구조체  (0) 2019.04.04
[C] 함수  (0) 2019.04.03
[C] 포인터  (0) 2019.04.02
[C, C++] VSCode 개발환경 세팅  (2) 2019.04.01

+ Recent posts