In a C/C++ program, is it correct for me to do this:
int i;
FILE **files = malloc(numFiles * sizeof(FILE *));
std::string file("foo"), ext(".bar");
char *num[10];
for (i = 0; i < numFiles; i++) {
files[i] = fopen((file + itoa(i, num, 10) + ext).c_str(), "w");
}
This is basically what I am doing, but I am not getting anything written to the files. They’re blank.
EDIT
I have fixed my problem. I thought I might be doing something wrong here, but it turned out to be elsewhere. Thanks for the responses, anyway.
Sure they are blanked, you did not write anything, you simply open the file in writing mode!
You have to use the fwrite or fprintf function to write the data to the file and then close the file with fclose.