a + mode

 In C, the a+ mode is used for file handling and stands for "append and read." When you open a file in a+ mode, you can do the following:

  • Append Data: You can write data to the end of the file. If the file does not exist, it will be created.
  • Read Data: You can also read data from the file, starting from the beginning.

Example

#include<stdio.h>
#include<conio.h>

int main(){

   FILE *fp;
   char ch;
   fp = fopen("D://program.txt", "a+");
   if (fp == NULL) 
    {
       printf("Error");
       exit(1);   
    }
    fputs("Welcome to my Blog",fp);
    rewind(fp);
    while(!feof(fp))
    {
     ch = fgetc(fp);
     printf("%c",ch);               
    }
    printf("\n Append Done successfully");
    
 fclose(fp);
getch();
return 0;
}

Output







No comments:

Post a Comment