Question
PLEASE HELP TO EDIT THIS CODE TO DISPLAY FROM TXT FILE. MAIN.C /* This program will read account information from the file account.txt and stores
PLEASE HELP TO EDIT THIS CODE TO DISPLAY FROM TXT FILE.
MAIN.C
/*
This program will read account information from the file account.txt
and stores the data on to an array of structure
The program then permits the user to perform a set of tasks
listed in the menu
*/
/*including header files */
#include
#include
/* include accounts.h file */
#include "mainr.h"
/* main function */
int main()
{
/* variable declaration */
struct empDetails record[MAXRECORD]; /* account structure variable */
int choice, /* holds menu choice */
records=0; /* holds total records */
FILE *fpt1; /* declaring file pointer */
printf(" ------------------------------------------------------------------");
printf(" This program will read account information from the file employee.txt");
printf(" and stores the data on to an array of structure");
printf(" The program then permits the user to perform a set of tasks");
printf(" listed in the menu");
printf(" ------------------------------------------------------------------");
printf(" Reading Data from employee,txt file ...... ");
fpt1=fopen("employee.txt","r");
if(!fpt1)
{
printf("\employee.txt file is not created.");
printf(" Please create the file with data to proceed");
return 0;
}
records=readFile(fpt1, record);
/* repeat until user choose to quit */
do
{
/* display menu */
printf(" -------------------------------------------- ");
printf("LIST OF TASKS THAT CAN BE SELECTED TO PERFORM ");
printf("-------------------------------------------- ");
printf(" 1. Display the Details ");
printf("-------------------------------------------- ");
/* validate input choice for 1-5 */
do
{
printf("Enter your choice of Action (1-5): ");
scanf(" %d", &choice);
if(choice<1 || choice>5)
printf("Invalid menu option. Must be within 1-5 ");
}
while(choice<1 || choice>5);
/* perform action based on user choice */
switch(choice)
{
/* display list of items */
case 1: listItems(record, records, 0);
printf(" Press Any Key to Continue....");
scanf("%*c%*c");
break;
}
}
while(choice!=5);
return 0;
}
MAIN.H
#ifndef outputdata
#define outputdata
/* include header files */
#include
#include
#include
/*setting maximum number of records */
#define MAXRECORD 10
/* declaring the account structure */
struct empDetails
{
char name[30];
int age;
int identity;
double salary;
};
/* function prototype declarations */
/*
Function to read data from employee.txt file
Input: account structure array and number of records
Output: None
Returns: The number of records.
Side Effects: The data read from the file is updated in the vintage structure array
*/
int readFile(FILE *fpt1, struct empDetails a[]);
/*
Function to display the list of items
Input: vintage structure array and number of records
Output: List of records
Returns: None.
Side Effects: None
*/
void listItems(struct empDetails a[], int rec, int save);
/*
Function to sort items using bubble sort based on account number
Input: account structure array and number of records
Output: Records are listed
Returns: None.
Side Effects: None
*/
int readFile(FILE *fpt1, struct empDetails a[])
{ int i;
for(i=0; !feof(fpt1); i++)
{
fscanf(fpt1,"%s %d %d %.2lf",
a[i].name,&a[i].age,&a[i].identity,&a[i].salary);
}
printf("Successfully Read %d Data Records from employee.txt File ",i);
printf("Press Any Key to Continue....");
scanf("%*c");
return i;
}
void listItems(struct empDetails a[], int n)
{ int i;
printf(" -----------------------------------------------------");
printf(" Name AGE ID SALARY");
printf(" -----------------------------------------------------");
for (int i = 0; i < n; i++){
printf("%s %d %d %.2lf", a[i].name,a[i].age,a[i].identity,a[i].salary);
}
printf(" ----------------------------------------------------");
return;
}
#endif outputdata
TXT FILE
Peter 30 1001 4000.11 Joseph 40 1003 6000.22 Mary 21 1002 5000.33 Lily 18 1004 7000.44 John 17 1006 9000.66 Alexa 25 1005 8000.55 Alvis 22 1007 10000.11 Felice 30 1008 11000.77 Wendy 27 1009 12000.88
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started