We can write a file in the following two modes.
1. Write mode
2. Append mode
Write (w) mode and Append (a) mode, both are used to write a file. The only difference between write and append mode is when you open a file in write mode the file reset and this reset process delete all the previous data of the file, while in Append mode, the cursor is positioned at the end of the last line in the file therefore new data will add without disturb the previous data of the file.
1. Write mode
2. Append mode
Write (w) mode and Append (a) mode, both are used to write a file. The only difference between write and append mode is when you open a file in write mode the file reset and this reset process delete all the previous data of the file, while in Append mode, the cursor is positioned at the end of the last line in the file therefore new data will add without disturb the previous data of the file.
PROGRAM TO WRITE FILE IN APPEND MODE
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
FILE *fp; //Create a file pointer
// Open file in writing mode
fp=fopen("test.txt","a");
//Wring content in "test.txt" file
fprintf(fp,"Welcome in first file");
printf("Data written in file successfully ...");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
FILE *fp; //Create a file pointer
// Open file in writing mode
fp=fopen("test.txt","a");
//Wring content in "test.txt" file
fprintf(fp,"Welcome in first file");
printf("Data written in file successfully ...");
getch();
}
----------------------------
OUTPUT
----------------------------
No comments:
Post a Comment