Hello everyone, first time asking for help as I haven’t found an answer to this anywhere and my attempts all result in errors. I’m writing a simulation and I need it to automatically create data files such as “results-1.dat”, “results-2.dat”, “results-3.dat” and so on. I read that this is possible in C (Create multiple files in C automatically - Stack Overflow), but I haven’t been able to replicate it in Go, be it with Sprintf or os.Create (os.Create doesn’t allow one to write something like “(“results%d.dat”, i)”, it seems).
Here’s the C code from the link above. Is a similar structure (loop) possible in Go? If not, how can I automatically create these files?
“FILE *files[numfiles];
for (int i = 0; i < numfiles; i++)
{
char filename[20];
sprintf(filename, “results%d.dat”, i);
files[i] = fopen(filename, “w”);
}”
Many thanks in advance!