I am getting this error on the last line of the code, as I am trying to read data from an extra.txt file. Records are read properly from an input.txt but not sure why it is throwing error for extra file. Thanks!
typedef struct {
char* fname;
char* lname;
int id;
int age;
} data;
typedef struct {
data** array;
int len;
int cap;
}vector;
vector* vector_read(FILE* in_file)
{
int i;
vector *v = (vector*)malloc(sizeof(vector));
fscanf(in_file,"%d",&v->len);
if(in_file=NULL)
{
return NULL;
}
printf("%d",v->len);
data** array = (data**)malloc(sizeof(data*)*(v->len));
v->array = array;
data *temp;
for(i=0;i<(v->len);i++)
{
temp = data_read(in_file);
v->array[i] = temp;
}
return v;
}
vector *v = vector_read(input);
printf( "initial state of vector v\n");
vector_print(v);
vector *v_add = vector_read(extra);
EDIT:
extra.txt has records in this fashion:
4
Barak Obama 101 50
Joe Biden 102 55
Joe Plumber 10293 45
Wayne Gretzky 99 56
and input.txt
1
Aaaa
Aooo
1
20
Your code needs go inside a function.
For example like this: