Program to write and read data from a file
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
char c;
FILE *fptr1;
clrscr();
printf("Enter the text to be stored in the file.\n");
printf("Use ^Z or F6 at the end of the text and press ENTER: \n\n");
fptr1 = fopen("COURSES.DAT","w");
while((c = getc(stdin)) != EOF){
fputc(c, fptr1);
}
fclose(fptr1);
printf("\nThe content of the file is : \n\n");
fptr1 = fopen("COURSES.DAT", "r");
do
{
c = fgetc(fptr1);
putchar(c);
} while(c != EOF);
fclose(fptr1);
getch();
}
Output:
Enter the text to be stored in the file.
Use ^Z or F6 at the end of the text and press ENTER:
Computer Science & Engineering
Information Technology
Electronics & Communication Engineering
^Z
The content of the file is :
Computer Science & Engineering
Information Technology
Electronics & Communication Engineering
-
UpdatedDec 31, 2019
-
Views5,422
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order