I have a struct, located in my header file, and I want to set its members to values I have in my main() function, those being "size" and "cap". I get the following: error: expected identifier or ‘(’ before ‘->’ token struct Array->size = size; I also get the same error for the line with "cap."
I've provided my header file, where the struct is found, and my function definitions file.
Header File:
#include <stdio.h>
struct Array {
unsigned int size;
unsigned int cap;
int data;
};
struct Array *newArray(unsigned int size, unsigned int cap); //Prototype
Function Definition File:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
struct Array *newArray(unsigned int size, unsigned int cap) {
struct Array->size = size;
struct Array->cap = cap;
}
I have intentionally not included my header file in my function definitions file because I include it in my main file. Having header.h included twice gives me more errors/warnings.
Could anyone please help? Thanks
struct Arrayis a type. You can't store values in a type. Create an instance of that type first (malloc some space).struct Arrayis the name of a type, not the name of a pointer variable which you can use the->operator with. You need to allocate memory for astruct Arrayfirst and then use the pointer to that memory.#include-ing your own header file, so the definition of the structure (or even that typeArrayexists) is unknown... that it is#included in the main file is irrelevant.