I am testing passing of struct array argument in struct function "push" but getting an error message of
"passing 'shelf' (aka 'struct shelf') to the parameter of incompatible type 'shelf *' (aka 'struct shelf *');".
How can I fix this error? I don't know what needs to be done in order to make it work. I have declared the structs and push function in the header file.
Main purpose of this program is to access the values of book struct in shelf struct.
Here are my code snippets.
header file
#ifndef __POINTERS_H_
#define __POINTERS_H_
typedef struct book
{
char *b_title;
int b_pages;
}book;
typedef struct shelf
{
char *s_title;
int s_pages;
}shelf;
book book_details[100];
shelf shelf_item[100];
shelf push(shelf item[100]);
#endif // __POINTERS_H_
c file:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pointers.h"
int main(void)
{
book book_details[100];
shelf shelf_item[100];
book_details[0].b_title = "c++";
book_details[0].b_pages = 200;
push(shelf_item[0]);
printf("Shelf Item's title is: %s\n", shelf_item[0].s_title);
printf("Shelf Item's title is: %i\n", shelf_item[0].s_pages);
return 0;
}
shelf push(shelf item[100])
{
strcpy(item[0].s_title, book_details[0].b_title);
item[0].s_pages = book_details[0].b_pages;
return item[0];
}
__POINTERS_H_identifiers with double underscores are reserved by C standard. Don't use them in your code.