c - How to access address of an array that is contained in a struct? -


i trying create program reading input file using getline.

i have created following struct

struct misc_struct {    char *buf;    file *some_input_file; }; 

in main file create buffer , multiple pthreads.

char buf[1024]; file *some_input_file; struct misc_struct *pthread_arguments; ... pthread_arguments = (struct misc_struct *)malloc(sizeof(struct misc_struct)); pthread_arguments->buf = buf; pthread_arguments->some_input_file = some_input_file; pthread_create(&t1, null, start, (void *)pthread_arguments); 

now in start function:

void *start(void *args) {     size_t len;     struct misc_struct *pthread_arguments = (struct misc_struct *)pthread_arguments;     getline(&args->buf,&len,args->some_input_file);     ... } 

unfortunately crashing @ getline() call. don't have trouble accessing args->buf when need use &args->buf getline function crashes "pointer being realloc'd not allocated"

what should doing differently? thanks!

char buf[1024]; : : : pthread_arguments->buf = buf;  getline(&args->buf,&len,args->some_input_file); 

i suspect getline() expects able free , realloc buffer given.

better give getline() pointer null buffer can alloc needs.

pthread_arguments->buf = 0; 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -