The problem here is that every time through the loop, you are assigning the same address (file_name) to the array. A simple way to solve this is strdup.



for(int ii=0; ii<=N-1; ii++){ //...