The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
44 views

#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 by (171 points) | 44 views

1 Answer

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]
by Junior (823 points)
0

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

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

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,376 questions
55,839 answers
192,571 comments
91,394 users