C program to create a file called emp.rec and store information about a person, in terms of his name, age and salary.

by Nideesh C on April 13, 2011 · 0 comments

in C Programming




/*  C program to create a file called emp.rec and store information about a person, in terms of his name, age and salary. */

#include <stdio.h>

void main()
{
FILE *fptr;
char name[20];
int age;
float salary;

fptr = fopen (“emp.rec”, “w”); /*open for writing*/

if (fptr == NULL)
{
printf(“File does not exists\n”);
return;
}

printf(“Enter the name\n”);
scanf(“%s”, name);
fprintf(fptr, “Name    = %s\n”, name);

printf(“Enter the age\n”);
scanf(“%d”, &age);
fprintf(fptr, “Age     = %d\n”, age);

printf(“Enter the salary\n”);
scanf(“%f”, &salary);
fprintf(fptr, “Salary  = %.2f\n”, salary);

fclose(fptr);
}

/*—————————————————————————
Output
Enter the name
Prabhu
Enter the age
25
Enter the salary
25000
————————————-
Please note that you have to open the file called emp.rec in the directory

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. Sample – Program to enter salary and output income tax and net salary.
  2. C program to accept the height of a person in centimeter and categorize the person based on height as taller, dwarf and average height person
  3. C program (1-D Array) store some elements in it.Accept key & split from that point. Add the first half to the end of second half
  4. C program to input N numbers (integers or reals) and store them in an array. Conduct a linear search for a given key number and report success or failure in the form of a suitable message
  5. 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

Leave a Comment

Previous post:

Next post: