I am trying to read a CSV file with such format.
902323;NewYork, newyork, US
43232;Mumbai, India
So I am trying to read the integer value and then everything else into a char till I hit the new line.
My code is as such:
datatype_t* read(FILE* fp, FILE* wfp)
{
 int weight;
 char *key;
 if (fscanf(fp, "%[^;],%[^\n]",weight,key) == 2) {
    printf("here\n");
    datatype_t *d = (datatype_t*)malloc(sizeof(datatype_t));
    if (d == NULL)
    {
        printf("No Space Allocated\n");
    }
    d->weight = strdup(weight);
    d->key= strdup(key);
    printf("%d", d->weight);
    return d;
}
else{
    printf("nothing\n");
}
return NULL;
}
So I have two files coming in from the main function, the first one is the file I read and the second one is the one I write to. I am getting seg faults on the fscanf line.
typedef struct{
     int  weight;
     char *key;
}datatype_t;
 
    