Let's say I have the following struct and array of that struct:
struct Fileinfo {
int ascii[128]; //space to store counts for each ASCII character.
int lnlen; //the longest line’s length
int lnno; //the longest line’s line number.
char* filename; //the file corresponding to the struct.
};
struct Analysis fileinfo_space[8]; //space for info about 8 files
I want to have a function that will add a new struct to this array. It must take a void pointer to the position where to store the struct as an argument
int addentry(void* storagespace){
*(struct Fileinfo *)res = ??? //cast the pointer to struct pointer and put an empty struct there
(struct Fileinfo *)res->lnlen = 1; //change the lnlen value of the struct to 1
}
My questions are:
What goes in place of ??? I tried
(Fileinfo){NULL,0,0,NULL}
as per this Stackoverflow response. But I get `error: ‘Fileinfo’ undeclared (first use in this function)How do I create a void pointer to the array? Is (void *)fileinfo_space correct?
I am required to use void *
as the argument for the function for this assignment. It's not up to me.