C Program for file operations.

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

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/



#include <stdio.h>

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

fptr = fopen ("emp.txt", "w"); /*open for writing*/

if (fptr == NULL)
{
printf("File does not existsn");
return;
}

printf("Enter the namen");
scanf("%s", name);
fprintf(fptr, "Name = %sn", name);

printf("Enter the agen");
scanf("%d", &age);
fprintf(fptr, "Age = %dn", age);

printf("Enter the salaryn");
scanf("%f", &salary);
fprintf(fptr, "Salary = %.2fn", salary);

fclose(fptr);
}
/*Please note that you have to open the file called emp.txt in the directory*/

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

Leave a Reply