#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *fptr;
char filename[15];
char ch;
printf(“Enter the file name to be opened\n”);
gets(filename);
fptr = fopen (filename, “r”); /*open for reading*/
if (fptr == NULL)
{
printf(“Cannot open file\n”);
exit(0);
}
ch = fgetc(fptr);
while (ch != EOF)
{
printf (“%c”, ch);
ch = fgetc(fptr);
}
fclose(fptr);
} /* End of main () */
/*———————————————-
Output
Enter the file name to be opened
emp.rec
Name = Prabhu
Age = 25
Salary = 25000.00
————————————————*/
Not Satisfied ? Just search & get the result
Related posts:
- C program to create a file called emp.rec and store information about a person, in terms of his name, age and salary.
- C program to illustrate the concept of unions
- C program to read N names, store them in the form of an array and sort them in alphabetical order. Output the give names and the sorted names in two columns side by side with suitable heading
- C program to read two strings and concatenate them (without using library functions). Output the concatenated string along with the given string
- C program to read an English sentence and replace lowercase characters by uppercase and vice-versa. Output the given sentence as well as the case converted sentence on two different lines.
