The r+ mode for opening a file is similar to the r mode but has some added features. It opens the file in both read and write mode.
However, the main purpose of r+ is reading. If the file exists, it will be opened for both reading and writing, but if the file does not exist, a new file will not be created.
Note - This mode has modification facility.
Example
#include<stdio.h>
#include<conio.h>
int main(){
FILE *fp;
fp = fopen("D://program.txt", "r+");
if (fp == NULL)
{
printf("Error");
exit(1);
}
fputs("C Programming",fp);
printf("\n Modify data successfully");
fclose(fp);
getch();
return 0;
}
#include<conio.h>
int main(){
FILE *fp;
fp = fopen("D://program.txt", "r+");
if (fp == NULL)
{
printf("Error");
exit(1);
}
fputs("C Programming",fp);
printf("\n Modify data successfully");
fclose(fp);
getch();
return 0;
}
Output
No comments:
Post a Comment