#include <stdio.h>
#include <stdlib.h>
typedef struct{
int lab;
int arr[20];
int vac;
}bookings;
void checkIn(bookings *in)
{
printf("It is %i",in[0].arr[0]);
}
int main(){
bookings b[5];
int a,c;
/*Initializing struct variables*/
for(a=0;a<5;a++)
{
for(c=0;c<20;c++)
{
b[a].arr[c]=0;
b[a].vac=20;
/*printf("Lab %i PC %i is %i\n",a,c,b[a].arr[c]);*/
}
/*printf("Lab %i has vacant %i\n",a,b[a].vac);*/
}
b[0].lab=101;
b[1].lab=201;
b[2].lab=301;
b[3].lab=401;
b[4].lab=501;
checkIn(&b);
return 0;
}
Based on the code, I've assigned values of 0 into the arr[20] array and in each struct, the vac value will be 20. What I'm trying to do is to pass the array of structs into the function and read the value in the function. According to what I've read so far, using the pointers in the function parameters and passing the array of struct address should work.
When compiled, it displays the error,'error passing argument1 of checkIn from incompatible pointer type'. My expected output is
It is 0
Any help would be quite appreciated!
checkIn(b)orcheckIn(&b[0])should work.checkIn(b)not address ofb, you're currently technically passing in a pointer to a pointer to the first element