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

int check(char *); //char * 하나를 받아서 int를 반환하는 check 함수, 문자 포인터를 매개변수로 받음

int main(void) {
    int i, volume, count = 0;
    
    // char *words[] : 문자열을 가리키는 포인터들의 배열
    // words는 문자열 자체를 직접 저장하는 2차원 배열이 아니라,각 문자열의 시작 주소를 저장하는 배열
    char *words[] ={ "A","good","deed","Luck",
                     "students","level","rapport","reviver",
                     "successful","PASS" }; //회문인 문자열: A, deed, level, reviver
    
    printf("%s \n", *(words+4)); //*(words+4) = words[4]: students    

    ////words 전체 배열의 크기: 10, sizeof(char*): 문자 포인터 하나의 크기
    volume = sizeof(words)/sizeof(char*); //sizeof(words): 8 * 10 = 80, sizeof(char*) = 8 -> 80/8

    printf("volume = %d \n", volume); //volume: 10
    
    for(i=0; i<volume; i++)
        if(check(words[i])) //words[i]: 문자열 자체가 아닌 문자열의 시작주소 (Y:*words[] )
            count++; //회문인 경우에만 count를 증가
    
    printf("%d", count); //count: 4
} 

//C에서 문자열은 문자들이 연속으로 저장되고 마지막에 '\0'이 붙은 구조
//예)level -> 'l'  'e'  'v'  'e'  'l'  '\0'로 저장-> word는 이 문자열의 첫 글자 주소를 가르킴('l'), '\0' 는 길이에 포함되지 않음
int check(char *word){ //문자열이 회문인지 아닌지 검사하는 함수, C에서 문자열은 문자배열이
    int pt=0;
    int len = strlen(word);

    while(pt<(int)(len/2)){ //문자열의 앞쪽만 검사.(Y: 앞글자와 뒷글자만 비교하기때문)
        if(word[pt] != word[len-pt-1]) //앞 문자와 뒤 문자 비교
            return 0;
        pt++;
    }
    return 1;    
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: