I want to call a function which creates files periodically on every 5 seconds in C. The function code is below which creates files.
void file_create(int time) {
snprintf(filename, sizeof(filename),"%s_%d", "data", index);
FILE *fp = fopen (filename, "w");
index++;
}
file name will be data_0, data_1, data_2 and goes on on every call.
how to call the above function periodically every 5 seconds from main function if i put an infinite loop like below
while(1){
file_create();
Sleep(5000);
}
this is not allowing to execute the lines below the while loop.
How to achieve this by calling above function periodically without holding execution of rest of the program ?