All pastes #454626 Raw Edit

WoLpH

public c v1 · immutable
·published 2007-04-23 18:48 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <string.h>#define NO_EMPLOYEES 3#define MAXLENGTH 21 /* the maximum length of the names */typedef struct employee{	char firstname[MAXLENGTH];	char lastname[MAXLENGTH];	int id;	struct employee *next;}empl;empl* insert(empl *first, empl *new){	empl *cur, *prev;	if(first == NULL){		return new;	}	cur = first;	prev = first;	while(cur != NULL){		if(cur->id < new->id){			prev = cur;			cur = cur->next;		}else{			break;		}	}	if(first==cur){		first = new;		new->next = cur;	}else{		prev->next = new;		new->next = cur;	}		return first;}int main(int argc, char **argv){	empl *head, *temp;	int i;	head=NULL;		for(i=0; i<NO_EMPLOYEES; i++){		temp = (empl*)calloc(1, sizeof(empl));				printf("Please enter the first name, the last name and the user id:\n");		scanf("%s %s %d", temp->firstname, temp->lastname, &temp->id);		temp->next = NULL;		head = insert(head, temp);	}	printf("The employee with the lowest id number is\n");	printf("First name: %s\n", head->firstname);    printf("Last name: %s\n", head->lastname);    printf("User ID: %d\n", head->id);	temp = head;	printf("Here's a list with all employees\n");	while(temp != NULL){		printf("First name: %s\n", temp->firstname);	    printf("Last name: %s\n", temp->lastname);	    printf("User ID: %d\n", temp->id);		temp = temp->next;	}	return 0;}