c - while ... readdir causing segementation fault -
in main call following function deletefolder():
void deletefolder(){ struct dirent *next_file; dir *folder; char filepath[256]; folder = opendir("./game/wow"); while((next_file = readdir(folder)) != null){ //this causing segmentation fault. dont know why?? sprintf(filepath, "%s/%s", "./game/wow", next_file->d_name); remove(filepath); } }
i can't figure out why happening?
while((next_file = readdir(folder)) != null){ //this causing segmentation fault. dont know why??
i suspect there error in opening directory. add error checking code.
folder = opendir("./game/wow"); if ( folder == null ) { perror("unable open folder."); return; } while((next_file = readdir(folder)) != null){ ...
Comments
Post a Comment