Please see this piece of code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main() {
int i = 0;
FILE *fp;
for(i = 0; i < 100; i++) {
fp = fopen("/*what should go here??*/","w");
//I need to create files with names: file0.txt, file1.txt, file2.txt etc
//i.e. file{i}.txt
}
}
To change the name of a file in Windows, simply go to the folder list and right-click on the file or folder you want to rename. You will then see a menu that includes Rename; this allows you to rename the document.
Include files in C++ always have the file name extension ". hh". Implementation files in C++ always have the file name extension " . cc ".
for(i = 0; i < 100; i++) {
char filename[sizeof "file100.txt"];
sprintf(filename, "file%03d.txt", i);
fp = fopen(filename,"w");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With