(Proficient at C++, newbie at C) getting a segfault error from the addArray() call in main(). I've checked many posts and several texts, it compiles, but no luck running it. I'm coding it on VS2015 and all the usual handy cues are there with pointers, etc. Cleary something I'm not aware of or a syntax error. This is the distilled code that reproduces the error.
#include<stdio.h>
#include <stdlib.h>
#define TYPE int
struct arrayHolder {
TYPE data[100];
int count;
};
//prototypes.
void initArray(struct arrayHolder * );
void addArray(struct arrayHolder *, TYPE);
int main() {
struct arrayHolder * myStruct = NULL;
initArray(myStruct);
addArray(myStruct, 123);
}
/* Allocate memory for struct arrayHolder */
void initArray(struct arrayHolder * b) {
b = (struct arrayHolder *)malloc(sizeof(struct arrayHolder));
b->count = 0;
}
/* Add an element to data[] */
void addArray(struct arrayHolder * b, TYPE v) {
int count = b->count;
b->data[count] = v;
(b->count)++;
}
void *to other pointers in C.