input file is

3
Abdul Rachel
Lopez Charlie
Schofield Theo

by writing kyle richards and the new employee, im trying to get an output like this.

Rachel Abdul
Charlie Lopez
Kyle Richards
Theo Schofield

So im trying to get it to write in alphabetical order to whatever employee name I type in.
This code that i have on the bottom is writing this to the output file.

Abdul
KyleLopez
KyleSchofield
Kyle

I ve been looking at this for a while and i dont know where to go next, any ideas why my code is not working?






Code:
#include <stdio.h>
#include <string.h>


struct record{
    char fname[20];
    char lname[20];
};


int namecmp (struct record eA, struct record eB);


int main() {
    FILE *ifp = fopen("input.txt", "r");
    FILE *ofp = fopen("roster.txt", "w");
    int num_people, i, flag=0;
    struct record new_employee, temp_employee;


    printf("What is the first name of the new employee?\n");
    scanf("%s", new_employee.fname);


    printf("What is the last name of the new employee?\n");
    scanf("%s", new_employee.lname);


    fscanf(ifp, "%d", &num_people);


    for(i = 0; i < num_people; i++){
    fscanf(ifp, "%s", temp_employee.fname);
    fscanf(ifp, "%s", temp_employee.lname);


    namecmp(new_employee, temp_employee);


    fprintf(ofp, "%s\n", &temp_employee);
    fprintf(ofp, "%s", &new_employee);


    }


    fclose(ifp);
    fclose(ofp);


    return 0;
}


/* Pre-Conditions: This function takes in two structures of type record.
 * These are labeled eA and eB for employee A and employee B, respectively.
 * Post-Conditions: This function compares the names of the two
 * employee to see which should come first lexicographically.
 * The function returns -1 if eA comes first, -1 if eB comes first,
 * and 0 if the employees have the same name.
 */
int namecmp (struct record eA, struct record eB) {
    if (strcmp(eA.lname, eB.lname) < 0)
        return -1;
    else if (strcmp(eA.lname, eB.lname) > 0)
        return 1;
    else {
        if (strcmp(eA.fname, eB.fname) < 0)
            return -1;
        else if (strcmp(eA.fname, eB.fname) > 0)
            return 1;
        else
            return 0;
    }
}