catch error please
가림새
질문 제목 : 질문 내용 : #include stdlib.h
#include stdio.h
#include sys/types.h
#include dirent.h
#include sys/stat.h
#include string.h
#include unistd.h
#define mpath 256void find_directory(dir *dir, char *path, char *string, char *ad);
int isdirectory(char *path);
main(int argc,char *argv[]) {
dir *dir;
char cwd[mpath];
if( (dir=opendir(argv[1])) == null )
perror(opendir error);
getcwd(cwd,mpath);
find_directory(dir,argv[1],argv[2],cwd);
closedir(dir);
}
void find_directory (dir *dir, char *path, char *string, char *ad)
{
dir *r_dir;
struct dirent *directory;
struct stat file_stat;
char buff[1024];
char answer[32];
char mycwd[mpath];
while( directory = readdir(dir) ) {
if( !strncmp(directory-d_name,.,1) )
continue;
if( directory-d_ino == 0 )
continue;
sprintf(buff, %s%s,path,directory-d_name);
if( strstr(directory-d_name,string) ) {
chdir(path);
if( getcwd(mycwd,mpath) == null )
perror(not exist working directory);
printf(%s%s\n,mycwd,directory-d_name);
chdir(ad);
}
if( isdirectory(buff) ) {
r_dir = opendir(buff);
find_directory(r_dir,buff,string,ad);
}
}
}
int isdirectory(char *path) {
struct stat statbuf;
if( stat(path,&statbuf)==-1 ) return 0;
else return 1;
}
도대체 무슨에러인가요; find_dir을 find_directory 로 이름만 다 바꿔준거거든요
그래도 에러가 다나네요 find_dir일떄도 나구요... 무슨에러인가요..
-
나빛
예 gcc로 컴파일은되는데 실행하면저오류가뜨네요
-
진달래
isDirectory() 함수가 제대로 동작하는지부터 확인해 봐야 하지 않을까요?
-
흡뜨다
엑박님 저기서 하위 디렉토리까지 검색을 해보려면 어떻게 해야할까요...전 그 부분까지 구현한다고 한건데 안되네요......
-
엄빠몬
컴파일을 어떻게 하셨는지 모르겠는데... 별도 옵션을 주지 않으시면 실행파일은 a.out으로 나옵니다.
./a.out 을 실행하셔야 겠지요.
만약 myfind로 만드셨다면, ./myfind 로 실행해야 할테고... -
가막새
GCC로 컴파일은 되는데 예 MYFIND.C 실행 하고 하믄 저렇게 오류가나네요
-
큰맘
컴파일을 하시려는 건가요? 실행을 하시려는 건가요?
실행파일이 myfind.c 라는 얘기?