ABOUT ME

Today
Yesterday
Total
  • 두 문자열 비교
    코딩/C언어 2019. 4. 4. 15:25
    반응형
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    #include <stdio.h>
    int stringEqual(const char *s1, const char *s2)
    {
        int i;
     
        for (i = 0*(s1 + i) != '\0'; i++)
        {
            if (*(s2 + i) == '\0')
                return 1;
     
            if (*(s1 + i) != *(s2 + i))
                return 1;
        }
     
        if (*(s2 + i) != '\0')
            return 1;
     
        return 0;
    }
    int main(void)
    {
        char string1[50];
        char string2[50];
     
        printf("Enter the first string:");
        scanf("%s", string1);
        printf("Enter the second string:");
        scanf("%s", string2);
     
        if (stringEqual(string1, string2) == 0)
            printf("두개의 문자열은 같다\n");
        else
            printf("두개의 문자열은 다르다\n");
    }
    cs

     

     

    결과:

    반응형

    '코딩 > C언어' 카테고리의 다른 글

    문자열 중 첫 단어 추출  (0) 2019.09.02
    약수 구하기  (0) 2019.09.01
    문자열 복사(포인터)  (0) 2019.04.04
    난수의 합(포인터, 배열)  (0) 2019.04.01
    난수의 합 (포인터)  (0) 2019.04.01
Designed by Tistory.