I need to open the files in the program automatically. For example, I have several files with the names - 10_04_16.txt, 11_04_16.txt, 12_04_16.txt and so on. open them individually is not a problem, but what if I want the program to open such files itself, that is, how to describe a loop that would open files with such names (the difference in the name of which is only 1 digit)? Has anyone encountered a similar task and what would you advise? PS I am writing a program in C.

  • For Windows, FindFirstFile / FindNextFile will allow you to sort files by mask in any directory. Next - a matter of technology. - Vladimir Martyanov

1 answer 1

For example, something like this:

for(int i = 10; i < 20; ++i) { char name[20]; sprintf(name,"%d_04_16.txt",i); FILE * f = fopen(name,"rt"); if (f) { /* ..... */ fclose(f); } } 
  • I use it in C. Bilder XE6, and load files in this way automatically, so only the last file is loaded into the Memo1 component, and I need to output everything - B.Leo