Fixed buffer overflow by allocating char arrays of size 1000 for filenames.