structure and a linked list help

This is a discussion on structure and a linked list help within the C Programming forums, part of the General Programming Boards category; I writing a program that, that utilizes a structure and a linked list to store employee information taken from the ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    2

    structure and a linked list help

    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);
    
    }
    Attached Files Attached Files

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by mikecool291 View Post
    This is what i have so far, I keep having a problem while compiling.
    Try being more specific. Most people would not drop a car off at an autoshop with a note saying "I have a problem using this car...any suggestions?"
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21