I have to generate a number of files based on a variable.
Is there a way to do this withou declaring the FILE (FILE *fptr)?
I've search a lot, and found about fstream, but this, apparently, only works with C++T
Thanks
Printable View
I have to generate a number of files based on a variable.
Is there a way to do this withou declaring the FILE (FILE *fptr)?
I've search a lot, and found about fstream, but this, apparently, only works with C++T
Thanks
Just call `fclose(fopen(filename, "w"));`.
If lack of clarity was a competition sport, you would win a fair few prizes.
What do you mean by "generate a number of files based on a variable"?????
The user will put a numer, like 3
And I have to generate 3 txt files.
Well then you would need a loop and some naming convention for your files (such as 1.txt, 2.txt, 3.txt)
Yeah, i think i know how to do this loop naming...
But, dont I need to declare the pointer to these files?
I dont know what number the user will put.
If was only 3 files, i could write
FILE *fptr1
FILE *fptr2
FILE *fptr3
Can I just declare one of this and rename the txt everytime i want to create a new file?
The name of the variable is meaningless. Naming a FILE pointer fptr1 does not mean it can only open a file on disk (or wherever) named fptr1.
Look again at claudiu's post. Imagine what would happen if the FILE pointer (whatever you choose to name it) was local to the loop body .....