Before starting with the programming part one should know the difference between the terms like file, append, read and write.
Read : Means Reading the file. Write : Means writing the file. Apend : Add (something) to the end of a written document.
For file handling in ‘C’, below are some keywords which we can use in our coding.
r: If we use ‘r’ , it means file is in read mode only.
w; If we use ‘w’ , it means file is in write mode only. If file exists then it will clear the data and write data into file. If file does not exist then it will create a new file.
a: It I called the append mode. If we use ‘w’ , it means file is in write mode only. If file exists then it will not clear the data and write data file after the last text was written. If file does not exist then it will create a new file.
r+: if file exist, then open a file both for reading and writing. If file does not exist then it will not create new one.
w+: if file exist, then open a file both for reading and writing. If file does exist then it will not create new one. It will truncate the file to zero length.
a+: it is called append plus mode. if file exist, then open a file both for reading and writing. If file does exist then it will not create new one. It will not truncate the file to zero length. Write data file after the last text was written.
If you want to use binary data then we can use "rb", "wb", "ab", "rb+", "r+b", "wb+", "w+b", "ab+", "a+b".
File is the keyword which is used to declare the file it is similar that we declare for variable like “ int a”.
Syntax : File *fp;
We need to provide the path of the file.
Fp= fopen(“D:\ WriteLines.txt”,”w+”);
How to write the text in a file?
We can use fprintf, fputs, fputc to write the text in a file.
Here is the small program which is helpful to under the basic of C.
Abhishek Srivasatava
28-Oct-2016Before starting with the programming part one should know the difference between the terms like file, append, read and write.
Read : Means Reading the file.
Write : Means writing the file.
Apend : Add (something) to the end of a written document.
For file handling in ‘C’, below are some keywords which we can use in our coding.
r: If we use ‘r’ , it means file is in read mode only.
w; If we use ‘w’ , it means file is in write mode only. If file exists then it will clear the data and write data into file. If file does not exist then it will create a new file.
a: It I called the append mode. If we use ‘w’ , it means file is in write mode only. If file exists then it will not clear the data and write data file after the last text was written. If file does not exist then it will create a new file.
r+: if file exist, then open a file both for reading and writing. If file does not exist then it will not create new one.
w+: if file exist, then open a file both for reading and writing. If file does exist then it will not create new one. It will truncate the file to zero length.
a+: it is called append plus mode. if file exist, then open a file both for reading and writing. If file does exist then it will not create new one. It will not truncate the file to zero length. Write data file after the last text was written.
If you want to use binary data then we can use "rb", "wb", "ab", "rb+", "r+b", "wb+", "w+b", "ab+", "a+b".
File is the keyword which is used to declare the file it is similar that we declare for variable like “ int a”.
Syntax : File *fp;
We need to provide the path of the file.
Fp= fopen(“D:\ WriteLines.txt”,”w+”);
How to write the text in a file?
We can use fprintf, fputs, fputc to write the text in a file.
Here is the small program which is helpful to under the basic of C.
We can use fscanf, fgets, fgetc to Read the text in a file.