I want to use previously malloc’ed array with a C getline function:
ssize_t getline(char **restrict, size_t *restrict, FILE *restrict)
The following code gives me EXC_BAD_ACCESS (code=1, address=0x400) :
FILE *in; if ((in=fopen(inpath, "r+w"))==NULL) exit(1);
char * buf = (char *) malloc (BUFSIZ); // BUFSIZ is constant, equal to 1024
if (getline(&buf, (size_t *)BUFSIZ, in)<0) return 1; // <--- EXC_BAD_ACCESS
How should I modify the code to make it working?
What you are doing now essentially tells
getlinethere’s a pointer to the address1024and you really want it to dereference it. Pass a real address as the second argument, don’t cast anintand hope for the best.