In C, I want to create and open text files to write data into, but the problem is I want to name the files on the go, such as
FILE *ptr;
for(i=0;i<1000;i++){
fopen_s(&ptr,"i.txt","w");
operations to fill data into file i.txt;
fclose(ptr);
}
such that I will create file 0.txt, 1.txt, 2.txt … 999.txt.
How is this possible? I checked open and rename functions, but couldn’t find a way to do.
Thank you so much for all your help.
Best,
use
snprintfto set the file number: