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.

Recommended Answers

All 3 Replies

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?

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

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.