I'm trying to enter a value into the struct I have in my header file. The value is given in the main file and is passed as an argument to a function. But I'm getting an error that says error: dereferencing pointer to incomplete type ‘struct Array’ array->size = size; The compiler is talking about the arrow in the line array->size = size; I have provided my files below.
Header.h:
#include <stdio.h>
//Include libraries used
struct Array {
unsigned int size;
unsigned int cap;
int data;
};
//Declare struct Array
struct Array *newArray(unsigned int size, unsigned int cap);
function.c:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
struct Array *newArray(unsigned int size, unsigned int capacity ) {
struct Array *array;
array->size = size;
}
My main.c file has included the header file so I don't have it in my function.c file. It also calls the function newArray(5, 20), giving size the value of 5. How do I fix this error so I can have size in the struct equal to 5? Thanks, I would really appreciate the help.
arraybefore attempting to dereference it. It's an undefined pointer value.struct Arraydoes not have memberwidth. Don't be sloppy, but also post the exact code you are trying, don't show us errors that don't apply to the code you post.