in Programming in C
463 views
0 votes
0 votes

#include<stdio.h>
int main()
{
    FILE *fp[2];
    if((fp[0]=fp[1]=fopen("test.txt","w"))!=NULL)  //test.txt file should be empty during first compiling
    {
        fputs("one",fp[0]);
        fclose(fp[0]);
        fputs("two",fp[1]);
        fclose(fp[1]);
    }
    return 0;
}

what will be printed in file “test.txt”. and also am not understanding what is done after “fputs("one",fp[0]);” and “fputs("two",fp[1]);”

can anyone tell me with explanation...please….

in Programming in C
by
463 views

1 Answer

0 votes
0 votes
one will be printed.

Reason:- fp[0] and fp[1] are having same reference i.e pointing to the same buffer for writing

Now when fp[0] writes one and close the buffer thereafter fp[1] write two but it does not go into the file as it is closed by fp[0]

3 Comments

if i write fopen("test.txt","w")) after fclose(fp[0]) the will effect???????????

0
0
It will overwrite previous written one with two because 'w' will clear all the data present in file and then write
0
0
okay thankyou....!
0
0

Related questions