C program to illustrate as to how the data stored on the disk is read

by Nideesh C on April 13, 2011 · 0 comments

in C Programming




/* C program to illustrate as to how the data stored on the disk is read */

#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 Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to create a file called emp.rec and store information about a person, in terms of his name, age and salary.
  2. C program to illustrate the concept of unions
  3. 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
  4. C program to read two strings and concatenate them (without using library functions). Output the concatenated string along with the given string
  5. 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.

Leave a Comment

Previous post:

Next post: