FilesStruct *old_dir;
memset(old_dir,0,sizeof(FilesStruct));
attempts to write to an uninitialised pointer. This results in undefined behaviour, including possibly a crash. Its just luck (good or bad, depending on how you look at it) that the first instance of this behaviour didn't crash.
You need to allocate memory for old_dir
. The easiest way to do this is to declare it on the stack
FilesStruct old_dir;
memset(&old_dir,0,sizeof(old_dir));
or you could dynamically allocate on the heap (making sure to call free
when you no longer need the object)
FilesStruct *old_dir = calloc(1, sizeof(*old_dir);
/* use old_dir */
free(old_dir);
The same applies to new_dir
further down your code.