sir kise file mai write karane ke leye kya stream create karte time O_WRONLY mood he deena necessary hoota hai. kya ham O_RDWR mood ka bhe use kar sakte hai.
Opening files in O_WRONLY and O_RDONLY is totally different thing.
open( FILE_NAME, O_WRONLY );
This mode is use to open file in write mode.
open( FILE_NAME, O_RDONLY );
This mode is use to open file in read mode.
CASE 1: If the file you want to open that does not even exist or you want to create the file and then open it in write mode.
open(FILE_NAME , O_CREAT | O_WRONLY);
It will create the file with the name you given and then open it in write mode.
CASE 2: If there is nothing written in the file.
Now, what is the point of open a book for read although you know there is nothing written in it.
So first we have to open file in write mode that will give us the lowest available number of file descriptor (fd : 3) write it and then open file in read mode.
CASE 3: Some text is in the file.
Now you can open the file in read mode to read the content from the file , store in an array and display it by using printf() or puts()