Advertisement
FILE *fopen(const char *filename, const char *mode)
File Mode | Description |
---|---|
"a" | Searches for the file and if the file is found, the pointer to its last character is returned. Allows you to append new data to the file. If file is not found, a new file is created. |
Greetings! Hope you are doing well.
#include<stdio.h>
#include<conio.h>
int main()
{
char str[100] = "Best wishes for all your endeavours!";
char ch;
/* This will append the data of char array the file named File1.txt */
FILE *fa = fopen("File1.txt", "a");
/* If the searched file is not found, the program exits */
if(fa==NULL)
{
printf("can not open target file\n");
exit(1);
}
int i=0;
/* If the file is found */
while(str[i]!='\0')
{
fputc(str[i], fa);
i++;
}
fclose(fa);
return 0;
}
Greetings! Hope you are doing well. Best wishes for all your endeavours!
Advertisement
Too much of work and no play made Jack a dull boy.
#include<stdio.h>
#include<conio.h>
int main()
{
char str[200];
printf("Enter the content you want to append to the file : \n");
gets(str);
/* this will create the file in the directory where this C program file is stored */
FILE *fa = fopen("File2.txt", "a");
/* If the searched file is not found, the program exits */
if(fa==NULL)
{
printf("can not open target file\n");
exit(1);
}
/* If the file is found */
char ch;
int i=0;
while(str[i]!='\0')
{
fputc(str[i], fa);
i++;
}
fclose(fa);
return 0;
}
Enter the content you want to append to the file :
Jack must also enjoy his life.
Too much of work and no play made Jack a dull boy. Jack must also enjoy his life.
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement