#include <stdio.h>

#include <string.h>

#include <dirent.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <unistd.h>

#include <string.h>



int main()

{

    char filename[4];


    DIR *dir_info;

    struct dirent *dir_entry;


    dir_info = opendir("./example");


    if(NULL != dir_info)

    {

        int i=0;

        while(dir_entry = readdir(dir_info))

        {

            //printf("%s\n", dir_entry->d_name);

            filename[i] = dir_entry->d_name;

        }


        closedir(dir_info);

    }


    for(int i=0; i<4; i++)

    {

        printf("%c\n", filename[i]);

    }


}


이 코드인데 filename 배열에 디렉토리 ./example 안에 있는 파일명을 넣고 싶은데 동작이 되긴 하는데 원하는 출력이 안나옵니다.


while코드 위에 주석으로 달린 것만 하고 printf("%c\n", filename[i]);를 지우면 디렉토리 내의 파일명이 잘 출력이 되긴 합니다만 그 파일을 배열에 넣고 싶은데 안될까요? 확장자를 검사하고 싶은데 어떻게 해야할지 모르겟습니다.