Write a program to store employee details and print it. sentence-level access.

/* Write a program to store employee details and print it. sentence-level access.*/

#include <stdio.h>

void main()

{

    int empno;

    char ename[20];

    float sal;

    FILE *fp;

    fp=fopen("c.txt","w");

    do

    {

        printf("Enter the employee number  : ");

        scanf("%d",&empno);

        fflush(stdin);

        printf("enter the employee name   : ");

        gets(ename);

        printf("Enter the salary : ");

        scanf("%f",&sal);

        fprintf(fp,"%4d %-20s %7.2f\n",empno,ename,sal);

        printf("Enter to continue;Escape to exit\n");

    }while(getch()!=27);

    fclose(fp);

    fp=fopen("c.txt","r");

    printf("Empno    Name                Salary \n");

    fscanf(fp,"%d %s %f\n",&empno,ename,&sal);

    while(!feof(fp))

    {

        printf("%4d %-20s %7.2f\n",empno,ename,sal);

        fscanf(fp,"%d %s %f",&empno,ename,&sal);

    }

    fclose(fp);

    getch();

}

Comments

Popular posts from this blog

Write a program to accept numerator and denominator and find the remainder without using modulus (%) operator using do..while loop.