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 ?

Unknown said...

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

Anonymous said...

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

Anonymous said...

can u answer my query?

Anonymous said...

can u answer me????/

Anonymous said...

can u answer me????/

Unknown 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.