W
webinfinite
I am starting a new thread for this topic since previous problem has
been solved.
I have code like this:
#include <stdio.h>
int main(){
FILE *fp;
while(1){
fp = fopen("foo.txt", "r"); ;
if (fp != NULL)
break;
else{
printf("Waiting for the file\n");
}
}
printf("I am out.\n");
fclose(fp);
return 0;
}
foo.txt is generated after this code starts to execute. My problem
here is that even after foo.txt has been generated, the code is still
in a tight loop printing:
Waiting for the file
Waiting for the file
Waiting for the file
Waiting for the file
Waiting for the file
Waiting for the file
Until long after the file is generated, the code comes out. Is there
any solution to force the code to find out if this file has been
generated?
Thank you.
been solved.
I have code like this:
#include <stdio.h>
int main(){
FILE *fp;
while(1){
fp = fopen("foo.txt", "r"); ;
if (fp != NULL)
break;
else{
printf("Waiting for the file\n");
}
}
printf("I am out.\n");
fclose(fp);
return 0;
}
foo.txt is generated after this code starts to execute. My problem
here is that even after foo.txt has been generated, the code is still
in a tight loop printing:
Waiting for the file
Waiting for the file
Waiting for the file
Waiting for the file
Waiting for the file
Waiting for the file
Until long after the file is generated, the code comes out. Is there
any solution to force the code to find out if this file has been
generated?
Thank you.