unix에서 readdir() 함수로 entry를 출력하는 함수인데요 출력이 잘안되네요
글쓴이: wcg0112 / 작성시간: 금, 2009/05/08 - 3:16오후
struct dirent* dir_list[300]; DIR* dir = opendir("path"); int cnt=0; int i=-1; while(dir_list[++i]=readdir(dir)); cnt=i; for(i=0;i<cnt;i++) printf("%s\n",dir_list[i]->d_name); closedir(dir); retutn 0;
/*path에 있는 entry를 출력하는 함수인데
readdit(dir)해서 포인터를 포인터 배열에 정리해서 출력할려구요
path entry의 수가 적을때는 잘 작동되는데
200개쯤되니까 dir_list[i]->d_name을 출력시
index 앞쪽에는 거지같은 문자들이 출력되네요;;
index 10 쯤 이후부터는 잘 출력되는데;;
무슨 문제인가요 ㅠㅠ*/
Forums:
readdir()의 return 값은
readdir()의 return 값은 static으로 할당된 struct dirent를 가리키는 포인터일 수 있으므로,
이 포인터 값을 배열로 잡아서 저장하는 것은 잘못된 코드입니다.
--
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Korean Ver: http://www.cinsk.org/cfaqs/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Korean Ver: http://cinsk.github.io/cfaqs/
댓글 달기