1,105,578 Community Members

Structures and Arrays

Member Avatar
Mindless Z
Newbie Poster
7 posts since Apr 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I'm working on a project and i'm having a bit of trouble.
the basic idea is to make an employee database using a basic structure. the program is to have 3 files and in the header file the professor wants the function prototype to be:

int addEmployee (struct employee *, int);

I've got the employee structure set up and the integer is just the current # of employee's so no problem there. My only real issue comes from the first parameter. We're supposed to have an array that stores every employee that is created, but i dont know how to create/'name' new employee's on the fly.

So my real question I guess is how do i set up my function call and definition?

Any help would be appreciated.

Member Avatar
zeroliken
Nearly a Posting Virtuoso
1,222 posts since Nov 2011
Reputation Points: 79 [?]
Q&As Helped to Solve: 216 [?]
Skill Endorsements: 15 [?]
 
1
 

We're supposed to have an array that stores every employee that is created, but i dont know how to create/'name' new employee's on the fly.

Does scanf on each index on the array doesn't solve your problem?

So my real question I guess is how do i set up my function call and definition?

Since I don't know what your structure looks like I'll make this example

struct x
   {
      int a;
      int b;
   };

   main()
   {
      struct x z;
	
      z.a = 5;

      printf("The first member is %d \n", z.a);   
   }

could you post your code for more details?

Member Avatar
zeroliken
Nearly a Posting Virtuoso
1,222 posts since Nov 2011
Reputation Points: 79 [?]
Q&As Helped to Solve: 216 [?]
Skill Endorsements: 15 [?]
 
1
 

Heres a more relevant example to your structure

struct emp{             //example structure
     char name[20];
  };

 void add(struct emp *employee,int n){
    int i;

        for(i=1;i<=n;i++){
          printf("Enter employee %i",i);	//my example on receiving input
          printf("\nEnter name:");
          scanf("%s",employee[i].name); 
        }
   }
 
  main()
  {
   int num = 5;			//defined number of employees
   struct emp employee[1000];	
   add(employee, num);         
  }
Member Avatar
Mindless Z
Newbie Poster
7 posts since Apr 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

My problem was i was trying to store the structures in a separate array instead of the structure itself creating the array. Thank you so much!

Question Answered as of 2 Years Ago by zeroliken
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: