This time it's about using a struct as a parameter. In this assignment I have to create a FIFS queue system. The static person queue is of the size 10. It means that just 10 persons can be on the queue.
I also have variables head, tail and nbr_elem of type static. The tail variable is used to add the person in a specific position. And vice_versa for the variable head. nbr_elem is the amount of persons in the queue. I think you don't need more information to help me. Now to the question:
How can I use a struct as a parameter in a function? This is what I have done so far:
static person queue[QUEUE_MAX_SIZE]; static int head = 0, tail = 0, nbr_elem = 0; struct person { char first_name[7]; char sur_name[10]; char pers_nbr[10]; }; void person_info(struct person p1){ /*printf("First name: ");*/ scanf("%s", &p1.first_name[7]); /* printf("Last name: ")*/; scanf("%s", &p1.sur_name[10]); /*printf("Id-number: ");*/ scanf("%s", &p1.pers_nbr[10]); } everything is fine so far but now I have to put struct person p1 in the queue by first copying the inf using the strcpy-function and then putting it to the array person queue[QUEUE_MAX_SIZE] i guess(?)
void enqueue( person queue[QUEUE_MAX_SIZE]) { queue[person_info(p1.first_name[7])]; } I don't even know if this is a good start of the function enqueue so I need some help here. And how can I use the static person queue[QUEUE_MAX_SIZE] in the function?
I also have a header-file queue.h that contains the typedef person. The header-file is then called to queue.c which is this file.