#includ<stdio.h>
FILE *f,*g;
void main()
{
//Some code
f=fopen("abc.log", "wt");
if(f==NULL)
DisplayError("\nabc.log Cant created ");
WriteData(f);
fclose(f);
// more code
g=fopen("xyz.log","wt");
if(g==NULL)
DisplayError("\nxyz.log cant be created");
}// main ends
void DisplayError( char *message) /* Routine for displaying the error messages. */
{ printf("%s\n", message);
printf("Program stopped !!\n");
exit(0);
}
Problem
2nd fopen always fails. i have tried it many times by changing file name like abc.txt, abc.dat file1.txt etc.
1st fopen succeeds.
please explain, why, what are various reasons that fopen can fail.
while running above program, no other file is opend.
i can create other files from DOS prompt, i mean no problem regarding disk space.
please chekc.
Thanks.
Is this the exact code? Can you verify if you have g=NULL in place of g==NULL?
Does the file exist and you have permissions for writing to it?
Regards,
sunnycoder