segfault in fscanf and struct question
hey people, i get a segfault in this fscanf call according to gdb.
is there anything obviously wrong with it? im certain there is.
Code:
while(fscanf(fp, "%ld", &input) != EOF)
{
data_set->data * = input;
data_set->items++;
}
here is my full main function:
in here i want to put input into the set_t struct (code section below)
Code:
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);
}
this is the struct i want to send my variables to. however im not sure how to use int *data properly
Code:
typedef struct
{
int *data;
int items;
int n_max;
int lock;
} set_t;
And here is set_create():
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);
}
everything before the fscanf works as it should im fairly certain.
thanks for any help.