Try and compile this and you'll see .
Code:
if((=fopen("Lamb.txt","w"))==NULL){}
(I see you changed it)
Also, you may want to deal with the cases when the file fails to open, and close the file when done:
Either nested:
Code:
int main()
{
FILE *file1;
FILE *file2;
if((file1 = fopen("Lamb.txt", "w")) != NULL)
{
if((file2 = fopen("Lamb_says_hello.txt", "w")) != NULL)
{
//*** Do whatever you want ***
fclose(file2);
}
else printf("Failed to open file 2");
fclose(file1);
}
else printf("Failed to open file 1");
return 0;
}
Or sequencially:
Code:
int main()
{
FILE *file1;
FILE *file2;
if((file1 = fopen("Lamb.txt", "w")) == NULL)
{
printf("Failed to open file 1");
return 0;
}
if((file2 = fopen("Lamb_says_hello.txt", "w")) == NULL)
{
printf("Failed to open file 2");
return 0;
}
//*** Do whatever you want ***
fclose(file1);
fclose(file2);
return 0;
}
Depends on which coding style you use.