hey people, i get a segfault in this fscanf call according to gdb.
is there anything obviously wrong with it? im certain there is.
here is my full main function:Code:while(fscanf(fp, "%ld", &input) != EOF) { data_set->data * = input; data_set->items++; }
in here i want to put input into the set_t struct (code section below)
this is the struct i want to send my variables to. however im not sure how to use int *data properlyCode:int main(int argc, char **argv) { long int input; /* Parse Arguments */ clo_t *iopts = parse_args(argc, argv); FILE *fp = fopen(iopts->input_file,"r"); /*allocates memory for data_set*/ set_t * data_set = set_create(500); data_set->items = 0; data_set->items++; while(fscanf(fp, "%ld", &input) != EOF) { /*not sure how to use this*/ data_set->data * = input; data_set->items++; } return (EXIT_SUCCESS); }
And here is set_create():Code:typedef struct { int *data; int items; int n_max; int lock; } set_t;
everything before the fscanf works as it should im fairly certain.Code:set_t * set_create(int size) { printf("size: %d\n", size); set_t * data_set = malloc(sizeof(set_t)); data_set->data = malloc(size * sizeof(int)); return(data_set); }
thanks for any help.



LinkBack URL
About LinkBacks



