Following is the C code with use of pointers and structures.

Here i want to fill a struct array of employees and then print the details of that array, sort the contents of that array alphabetically and swap them around.

Having trouble with pointer passing to the function.

Please reply asap.


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct employeeRecord
{
char surname[20];
double hourlyRate;
int empNumber;
};

typedef struct employeeRecord employee;

void fillEmployee(employee *emp, char name, double rate, int num);
void swap(employee employees[], int a, int b);
void sortEmployees(employee employees[], int number);
void printEmployees(employee employees[], int number);



int main()
{
employee employees[5];


fillEmployee(&employees[0], "Cogswell", 35.75, 43);
fillEmployee(&employees[1], "Alroy", 12.00, 163);
fillEmployee(&employees[2], "Jetson", 15.75, 97);
fillEmployee(&employees[3], "Astro", 10.25, 104);
fillEmployee(&employees[4], "Sprocket", 22.75, 15);

printEmployees(employees, 5);
sortEmployees(employees, 5);
printEmployees(employees, 5);

return 0;
}

void printEmployees(employee employees[], int number)
{
int i;

for (i=0; i<number; i++)
{
printf("%-20s%4d %.2f\n", employees[i].surname,
employees[i].empNumber, employees[i].hourlyRate);
}
printf("\n");
}

void swap(employee employees[], int a, int b)
{
/* code to swap employee a and b around in employees */

struct employee temp[5];

employees[a] = temp[0];
employees[b] = employees[a];
temp[0] = employees[b];

}


void sortEmployees(employee employees[], int number)
{
/* use insertion sort to order employees,
in employee name order
*/

int inner, outer;

for (outer=1; outer<number; outer++)
{
inner = outer;
while (inner > 0)
{
if (strcmp(employees[inner].surname, employees[inner-1].surname)
{
swap(employees, inner, inner-1);
inner++;
}
else break;
}
}
}