Can't creat as many files as need in a folder
Hello friends,
I hope there are some expert in Filestream programming with C.
First of all, sorry for my english. I'm not native english speaker.
I'm making some experiment with File streaming in C. In all the cases, until in the following one, the programs works as expected. But surprising, here not.
What is the program about?
I tried to write a program which creates as many files as needed in a folder. The name of the file does not change. Only the number of the file increase after every iteration by 1.
The program works prefect and as supposed, until (at arround) 500 files are created. After this, the program continues working without any problem, but no one new file is created in the folder.
I'm wondering why this happens. I took a look in Internet and it seems to me that the problem is not the OS. So I think it could be a problem with the buffer. But still cleaning the buffer does not helps.
Here the code:
Code:
#include <stdio.h>
int main(void)
{
unsigned int i = 0, count = 1;
// Max iteretions
const unsigned int MAX = 520;
unsigned char index_file_name = '0';
// Datafile name and place
char datafile_name[] = "many_files/datafile_name_00000.txt";
FILE *file_pointer_datafile = NULL;
//printf("Cantidad de vueltas> %i\n", MAX+1);
#define INDEX 29
printf("Program starts...\n");
// Loop is created with goto
while_GLOBAL:
// The new Filename is changed increasing the number by one
// So, first created file is named:
// datafile_name_00001.txt
// The next one
// datafile_name_00002.txt
// and so on.
if (index_file_name != '0') {
datafile_name[INDEX] = index_file_name;
}
else if (index_file_name == '0')
{
i = 0;
while (datafile_name[INDEX - i] == '9') {
datafile_name[INDEX - i] = '0';
i++;
}
datafile_name[INDEX - i] += 1;
}
// Creats the realtion between filepointer and new name of file.
file_pointer_datafile = fopen(datafile_name, "w+");
//printf("%i\n", index_file_name-48);
// Interrps the goto-loop when count is equal to MAX
if (count <= MAX) {
count++;
index_file_name++;
if (index_file_name > 57) {
index_file_name = '0';
}
//printf("%i\n", count);
goto while_GLOBAL;
} else {
printf("Programa finaliza...");
goto while_FIN;
}
// Hear I am trying to clean any posible buffer
fflush(stdin);
fflush(stdout);
fflush(file_pointer_datafile);
// Relation between filepointer and file is closed
fclose(file_pointer_datafile);
goto while_GLOBAL;
// End of program
while_FIN:
return 0;
}
What is happening? What I'm doing wrong?
Thanks for any good idea!
Gisi