The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
42 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….

asked in Programming by (171 points) | 42 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]
answered by Junior (789 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
49,808 questions
54,481 answers
188,249 comments
74,525 users