돌아가지가않아요ㅠㅠ
초코초코해
질문 제목 : 돌아가지가않아요 ㅠㅠ질문 요약 :돌리면 에러는안나고 앞에도 다정상출력되는데 case문 1번 선택하면 segmentation 오류가나요 질문 내용 : 이건 코드인데 뭐가잘못됫는지 모르겠어요...
#include sys/types.h
#include sys/stat.h
#include unistd.h
#include fcntl.h
#include dirent.h
#include stdio.h
char *outputfile;
char *defaultdir;
void init_output(char *dir){
FILE *fp, *fp2;
char buf[256];
char str[1024];
fp = fopen(outputfile, r);
fscanf(fp, %s, buf);
printf(outputfile open\n);
DIR *dirp;
struct dirent *dentry;
struct stat finfo;
dirp = opendir(dir);
printf(dir open\n);
while(dentry = readdir(dirp))
if(dentry-d_ino != 0) {
if(strcmp(..,dentry-d_name)==0 ||
strcmp(.,dentry-d_name)==0)
continue;
stat(dentry-d_name,&finfo);
sprintf(str,md5sum %s tmp,dentry-d_name);
system(str);
fp2 = fopen(tmp, r);
fscanf(fp, %s, buf);
remove(tmp);
fprintf(fp, %s %o %d %d %s\n,dentry-d_name,
finfo.st_mode, finfo.st_uid, finfo.st_gid, buf);
}
closedir(dirp);
}
void initialize(){
FILE *fp;
char buf[1024];
char buf2[1024];
fp = fopen(./config.txt, r);
fscanf(fp,%s,buf);
printf(open\n);
defaultdir = buf;
printf(%s\n,defaultdir);
fscanf(fp,%s, buf2);
outputfile = buf2;
printf(%s\n,outputfile);
init_output(defaultdir);
}
void show_files(char *dir){
char buffer[256];
DIR *dirp;
struct dirent *dentry;
struct stat finfo;
dirp = opendir(dir);
while(dentry = readdir(dirp))
if(dentry-d_ino != 0) {
printf(%s\n, dentry-d_name);
if(strcmp(..,dentry-d_name)==0 || strcmp(.,dentry-d_name)==0)
continue;
stat(dentry-d_name,&finfo);
if(S_ISDIR(finfo.st_mode))
show_files(dentry-d_name);
}
closedir(dirp);
}void main(){
int option;
initialize();
while(1){
scanf(%d,&option);
switch(option) {
case 1:
show_files(defaultdir);
case 3:
break;
default:
printf(Please Enter the Integer Number between 1 and 4);
}
}
exit(1);
}
-
훌걸이 2023-05-08
이코드 그대로돌린건데.. 질문요약에 나름쓴다고썼는데 부족했나보네요
-
뿌우 2023-05-08
코드가 전부 다 있는것도 아니고... 에러 메시지를 적어주신 것도 아니고
시간내서 봐드리고 싶어도 봐 드릴수가 없네요