C fscanf ignore commas

#include <stdio.h>

int main() {
    FILE *file;
    char word[50];

    file = fopen("input.txt", "r");

    if (file == NULL) {
        printf("Error opening the file.\n");
        return 1;
    }

    while (fscanf(file, "%49[^,\n]", word) == 1) {
        printf("%s\n", word);
        fgetc(file); // Skip the comma or newline
    }

    fclose(file);
    return 0;
}

This C code snippet reads from a file named "input.txt" and uses fscanf to extract words until it encounters a comma or a newline. It ignores the commas in the input file while reading the words.