Hi everyone, I am having trouble creating a table from a array, the array has 4 members being; first name, last name, hours, and payrate, from this the program asks for user input of these 4 members 3 times, then after that, it is supposed to create a table like this;
First Last Hours Payrate
=======================
1st 2nd 34545 2134
1st 2nd 34545 2134
1st 2nd 34545 2134
I can't get it work properly, any help will be appreciated.
Code:
#include <stdio.h>
#include <stdlib.h>
#define SIZE 3
struct employee
{
char first[20];
char last[20];
float hours;
float payrate;
};
typedef struct employee emp;
int main(void)
{
system("clear");
emp emps[SIZE];
int counter;
for (counter = 0; counter < 3; counter++)
{
input(&emps[counter]);
}
for (counter = 0; counter < 3; counter++)
{
output(emps[counter]);
}
emptable();
return 0;
}
void output(struct employee s)
{
printf("First: %s \n", s.first);
printf("Last: %s \n", s.last);
printf("Hours: %f \n", s.hours);
printf("Payrate: %f \n", s.payrate);
puts("********************************");
}
void input(emp * ptr)
{
printf("Enter first name: ");
scanf("%s", ptr->first);
printf("Enter last name: ");
scanf("%s", ptr->last);
printf("Enter hours worked: ");
scanf("%f", ptr->hours);
printf("Enter payrate: ");
scanf("%f", ptr->payrate);
puts("********************************");
}
void emptable()
{
int counter;
printf("%10s %10s %10s %10s", "First", "Last", "Hours", "Rate");
puts("------------------------");
for (counter = 0; counter < SIZE; counter++)
{
printf("%10s %10s %10d %10d \n", s.first, s.last, s.hours, s.rate);
}
return 0;
}