int file [1000] = {}; ... // shuffle for random reads random_shuffle(&file[0], &file[num_files]); This accesses beyond the end of the buffer. There are more issues with this code.