'Issues Reading a CSV file into a C Struct

I've just started learning C, and I'm currently trying to create a program to automate a fishing minigame I made for my D&D campaign. In order to do so, I created a CSV containing all the tables I had originally written up. I've been trying a variety of things for about a week now to just simply read the CSV into C so that I can call specific elements at will. I've finally gotten something to very nearly work, but I'm getting a strange problem. Firstly, the CSV is formatted as such:

bluefish,str,2,5
bluefish,str,2,5
bluefish,str,2,5
bluefish,str,2,5
kahawai,dex,2,1000
narrow barred mackerel,str,3,5

It goes on for another 400 lines, but you get the point. My current code looks like the following:

typedef struct{
    char name[50];
    char contest[5];
    int modifier;
    int value;
} fts_t;




    /*Checking for the file and opening it*/
    FILE *tpointer;

    tpointer = fopen("fishing_tables.csv", "r");
    printf("Accessing Fishing Tables...\n");

    if(tpointer == NULL){
        
        printf("Error: Missing fishing_tables.csv");
        return 0;

    } else{

        printf("Success! Importing Data...\n");

    }

    
    /*Creating a struct array and initializing variables*/
    fts_t ft[400];
    char buffer[1024];
    int count = 0;
    char name[100];
    char contest[3];
    int modifier;
    int value;

    while(fgets(buffer, 1024, tpointer)){
        sscanf(buffer, " %[^,],%[^,],%d,%d", name, contest, &modifier, &value);
        strcpy(ft[count].name, name);
        strcpy(ft[count].contest, contest);
        ft[count].modifier = modifier;
        ft[count].value = value;
        printf("%s\t%s\t%d\t%d\n", ft[count].name, ft[count].contest, ft[count].modifier, ft[count].value);
        count++;
    }

So, following above, I'm having it print out the elements of the struct at each count as it loops, just to check that it's creating the struct correctly. The problem comes in that the output looks like this:

        dex     2       15

        dex     2       15

        dex     2       15

        dex     2       15

        dex     2       15

next    0       0       0

next    0       0       0

next    0       0       0

next    0       0       0

next    0       0       0

Now, hilariously, the rows beginning with "next" are the only rows printing correctly. I have these added in for some extra shenanigans in the context of the minigame, but what's important is that those are correct. However, in every other row, the name variable is not being read, and I'm really lost as to why, when the "next" rows are functioning fine. I've checked the actual variable itself, and it appears there's some sort of problem in my sscanf statement.

Any help is appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source