How to use the C program for multiple files


I have C program which take two argument, 1st is filename.txt and 2nd is some parameter. And, finally generate some score. Now, I have 10,000 of file in folder naming 1.txt .... 10,000.txt, and I want to calculate score of all the 10,000 file using that C program and want to put all the score in the file result.txt.

How can I automatize this thing.

You can do two things

  1. Write an external script that calls your program sequentially with all the files as arguments.
  2. Alter your program so that it cycles over all the files. You can use sprintf to iterate over the filenames.

     char filename[50];
     for (int i = 1; i < 10000; ++i) {
       sprintf(filename, "%d.txt", i);
       FILE* file = fopen(filename);
       // .. do stuff