Missing Employee Numbers File Handling coderinme

Missing Employee Numbers File Handling coderinme

Missing Employee Numbers File Handling coderinme
You are given a data file emp.txt with the following record structure:
struct employee { int empno; char name[3], int basic, grade; };
Every employee has a unique empno and there are supposed to be no gaps between employee numbers. Records are entered into the data file in ascending order of employee number, empno. It is intended to check whether there are missing employee numbers. Write a program segment to read the data file records sequentially and display the list of missing employee numbers.

#include<stdio.h>
struct employee
{
int empno;
char name;
int basic,grade;
};
int main()
{
FILE *inp;
struct employee e[100];
int i = 0,j = 1,t;
inp = fopen("emp.txt","r");
while(!feof(inp))
{
fscanf(inp,"%d %s %d %d",&e[i].empno,&e[i].name,&e[i].basic,&e[i].grade);
i++;
}
t=i;
printf("Missing employee numbers are:");
for(i=0;i< (t-1);i++)
{
if(j==e[i].empno)
j++;
else
{
printf("\n%d\n",j);
j=j+2;
}
}
fclose(inp);
getch();
return 0;
}

For more programs in C, visit our C Coder Archives

Missing Employee Numbers File Handling coderinme

Missing Employee Numbers File Handling coderinme

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.