Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8920983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:25:04+00:00 2026-06-15T06:25:04+00:00

In this program, I would like to print out information about people: the names

  • 0

In this program, I would like to print out information about people:

  • the names
  • their ages
  • their job type
    • student
    • staff
    • or neither

If the job type is a student, the student will have a course. If the job type is a staff then it will have a lecture room.

I want this to be determined by the enum typeofpeople. Then I’d like to call insert to put elements into a list, and then print them out in the main().

I’m getting the following errors:

 error: array type has incomplete element type
 part5.c:9:27: error: 'student' undeclared here (not in a function)
 part5.c:9:44: error: 'staff' undeclared here (not in a function)
 part5.c:9:56: error: 'neither' undeclared here (not in a function)

Here’s my code:

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

 char names[][7]= {"Simon", "Suzie", "Alfred", "Chip", "John", "Tim",
  "Harriet"};
 int ages[7]= {22, 24, 106, 6, 18, 32, 24};

 enum typeofpeople type[]={student, student,staff,staff,neither,student,staff};

 char* course[]={"java1","java2","java3"};
 char* rooms[]={"lab1","lab2","lab3"};

 //a coutc for course, and room
 int countc, countr;

 union nextinfo{
   char* course;
   char* rooms;
 };


 /* declare your struct for a person here */
 typedef struct Record{
   char *name;
   int age;
   enum typeofpeople type;
   struct Record *next;
   union nextinfo info;
 }Record;

 //set the head pointer at the start of the list
 Record *headptr = NULL;

 /* compare two string */
 char compare_people_by_name(char *a, char *b)
 {

   return strcmp(a, b);
 }

 int compare_people_by_age(int a, int b)
 {
   if (a<b)
     return -1;
   else if (a>b)
     return 1;
   else
     return 0;  
 }

 void insert (char *s, int n, enum typeofpeople type,int(*compar)(int a, int b)) {

 Record *t, *pnew, *prv;

 prv=NULL;

 pnew=(Record *)malloc(sizeof(struct Record));

 if(pnew == NULL){  
    abort();
    printf("memory allocation fail"); 
    exit(1);  
}else{
    printf("memory allocation to person  - %s - \n", s);      
}

 pnew->name = s;
 pnew->age = n;
 pnew->next = NULL;
 pnew->type=type;

 //check type of people
 if(type==staff){      
   pnew->info.rooms=rooms[countr];
   countr++;
 }else(type==student){   
   pnew->info.course=course[countc];
   countc++;
 }

 //if the list is empty
 if (headptr==NULL)
 { 
    //add the first into the list
    headptr = pnew;
    return;
 }

 // look for the right place to insert
 for (t=headptr;t!=NULL;t=t->next) { 
     if (compar(n,t->age)<0) {        
        pnew->next=t;
        if (prv!=NULL)
           prv->next = pnew;
        else
           headptr=pnew;
        return;
     }
     //break the for loop.
     prv=t; 
 }
 prv->next=pnew;
 return;       
 }

 int main(int argc, char **argv) {

   Record *p, *q;

    countr=0;
    countc=0;

   for (int i=0; i < 7; i++) {
      insert (names[i], ages[i],type[i],compare_people_by_age);
   }

    printf("\n");
   Record *display;
   display=headptr;

   for (p = headptr; p!=NULL; p = p->next) {
     printf("The name is: %s, the age is:%i\n", p->name, p->age);

     if(display->type=staff){

  printf("room is %s\n",rooms);
}else if(display->type=student){
  printf("course is %s\n",course);

}else{
  printf("neither");

}
display=display->next;
   }


   /* To free your linked list: */

   p = headptr;

   while (p!=NULL){

q = p;
p = p->next;
free(q);
   }
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:25:06+00:00Added an answer on June 15, 2026 at 6:25 am

    This line is the problem:

    enum typeofpeople type[]={student, student,staff,staff,neither,student,staff};
    

    You need something like this:

    enum typeofpeople {
       student,
       staff,
       neither
    } type[]={student, student,staff,staff,neither,student,staff};
    

    Next problem:

    This line is wrong:

    if(display->type=staff){
    

    You really want:

    if(display->type==staff){
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GUI program, which would call a cmd in this GUI program.
This program builds a dictionary out of a list based on what two index
ok, so there's basically 3 tasks this program must carry out: Parse a sentence
I have a simple program where I would like to save an arraylist to
I need to gain some run-time information about a C++ program, which is kinda
After learning about how to print out debug messages using Visual Studio's Tracepoint feature,
I have a real world program that is similar to this one, which I'll
I have this problem when trying to run hello world program using android SDK.
I wrote this small C++ program and built it(Release) #include<iostream> int main(){ std::cout<<Hello World;
This program returns: package main import ( flag fmt ) func main() { num_agents

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.