0

In file handing mode "w" , does it overwrite the file and makes it empty?

Or it just points the first character the file pointer allow it to be written again ?

2nd Jan 2019, 10:45 AM
Sahil Bhakat
Sahil Bhakat - avatar
5 Answers
+ 4
"r" means `read`. It just opens a file in the reading mode, and not writing which is indicated by "w" or "w+". ________ https://en.cppreference.com/w/c/io/fopen
2nd Jan 2019, 10:52 AM
Babak
Babak - avatar
+ 2
I think that depends on the programming language. Usually I'd expect something like this: r (read): read from file. If file doesn't exist, throw an error. Writing to file isn't possible w (write): create new file in case it doesn't exist, write to file. If file does exist, the previous content is overriden a (append): same as "w", but if file already exists, append text to the existing content of the file w+/r+/a+: Open file for read and write operations. You can both read from and write to the same file > Or it just points the first character the file pointer allow it to be written again ? I don't think there's a special file mode for that. You'd probably need to open the file in w+ (or r+?) mode, jump to the beginning of the file, and use some kind of buffer to replace the existing content with the new content... đŸ€” But again, there might be differences between the programming languages, so better check explicitly for your language (and better play around with some dummy files before you test your program on real files)
2nd Jan 2019, 11:19 AM
Anna
Anna - avatar
0
Or sorry sorry my mistake i was writing "w"
2nd Jan 2019, 11:00 AM
Sahil Bhakat
Sahil Bhakat - avatar
0
I was asking for c programming
2nd Jan 2019, 11:23 AM
Sahil Bhakat
Sahil Bhakat - avatar
0
Anna See the message that i have sent you
2nd Jan 2019, 11:32 AM
Sahil Bhakat
Sahil Bhakat - avatar