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

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -