Thursday, 16 November 2017

C Program to Create a File & Store Information


Code:

#include   stdio.h

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

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

    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
raj
Enter the age
40
Enter the salary
4000000


More C Programs:












100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...