I writing a program that, that utilizes a structure and a linked list to store employee information taken from the keyboard (last name, first name, three digit employee id number). The program should traverse the linked list and display the name and id number of the employee with the lowest id number.
This is what i have so far, I keep having a problem while compiling. Does anyone have suggestions
Code:
//program to display link list
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define unam 20
typedef struct employee
{
char fnp[unam];
char lnp[unam];
int id;
struct employee*next;
}job;
job* insert(job *first, char FNP[], char LNP[], int idnum);
void traverse_and_print(job *head);
int main (void)
{
job *head, *p;
char enf[21],
enl[21];
int empID,
b,
x;
char ch,
nl;
head=NULL;
/*ok*/
for(x=0;x<21;x++)
{
enf[x]=' ';
enl[x]=' ';
}
for(b=0;b<4;b++)
{
printf("Type in employee first name: \n");
gets(enf);
printf("Type in employee last name: \n");
gets(enl);
printf("Enter user three digit ID: \n");
scanf("%d", &empID);
head=insert (head, enf, enl, empID);
for(x=0;x<21;x++)
enf[x]=' ';
enl[x]=' ';
}
p=head;
while (p!=NULL)delete this line
{
puts(head->fnp);
puts(head->lnp);
printf("The ID number is: ", head->id);
p=p->next;” “
}
printf("enter any character to go on");
scanf("%c", &ch);
}
job* insert (job *first, char empFNP[], char empLNP[], int idnum)
{
job *p,
*q,
*newp;
int found,
len,
i;
found=0;
q=first;
p=first;
while ((p!=NULL) && (!found))
{
if (p->id<idnum)
{q=p;
p=p->next;
}
else
found=1;
}
newp=(job*) malloc(sizeof(job));
newp->id=idnum;
strncpy(newp->fnp, LNP, 21);
insert a strncpy first name
strncpy(newp->fnp, _, 21); add 2 da blank line
newp->next=p;
if(q!=p)
q->next=newp;
else
first=newp;
return (first);
}