What is difference between file opening mode r+ and w+ in c?




Both r+ and w+ we can read ,write on file but r+ does not truncate  (delete) the content of file  as well it doesn’t create a new file if such file doesn’t exits while in w+ truncate the content of file as well as create a new file if such file doesn’t exists.

7 comments:

Anonymous said...

if w+ truncates the contents of file ,then how w+ can b used for reading operation ?

Angel Demons said...

w+ create and open file for reading and writing it can discards previous contents. it behaves like w with option of reading..

ibraheem anwar said...

what does the following modes perform in c lang?
"r+" "a" "r"
and how many modes are there in c lang?

ibraheem anwar said...

can u answer my query?

ibraheem anwar said...

can u answer me????/

ibraheem anwar said...

can u answer me????/

abhishek kumar said...

in file handling there are 5 modes mainly : r , w, a, w+ , r+ but there are some additional modes also available depending upon the type of file : text or binary . if you need to work on binary files the use b after above mode e.g rb,wb,ab,w+b,r+b. by default mode is text mode if needed then use t instead of b i.e w+t, rt etc.