'Updating a file containing an array of structures in C

I need to change only one element of an int array in a structure array and "update" it into the folder. Here is my code:

This is the structure

typedef struct studenti
    {
        char index[10];
        char ime[20];
        char prezime[20];
        int kviz[10];
    } studenti;

My main

int main(){
    studenti student[120];
    pretraga(file, student);
}

Function

void pretraga(FILE *file, studenti student[120])
{
    int odabir;
    int unos;
    int bodovi;
    int index;
    char s[20];
    fopen("studenti_2022.txt", "r+");

    printf("Unesite prezime:");

    scanf("%s",s);
    for(int i = 0; i < 120; i++)
    {
        if(strcmp(student[i].prezime,(s))==0)
        {
            printf("%s\n%s\n%s\n", student[i].index, student[i].ime, student[i].prezime);
            for (int j = 0; j < 10; j++)
            {
                printf("%d ", student[i].kviz[j]);
            }
            printf("\n");
        }
    }
    fopen("studenti_2022.txt", "r+");
    do
    {
        printf("Da li zelite urediti kviz(1-DA, 0-NE)?");
        scanf("%d", &odabir);
        if(odabir == 1){
            do
            {
                printf("Unesite koji kviz zelite urediti: ");
                scanf("%d", &unos);
                index = unos - 1;
                if(unos > 0 && unos < 11)
                {
                    do
                    {
                        printf("Unesite broj bodova: ");
                        scanf("%d", &bodovi);
                        if(bodovi > 0 && bodovi < 21)
                        {
                            for (int j = 0; j < 10; j++)
                            {
                                if(j == index)
                                {
                                    for(int i = 0; i < 120; i++)
                                    {
                                        if(strcmp(student[i].prezime,(s))==0)
                                        {
                                            student[i].kviz[index] = bodovi;
                                            printf("\n\n%d\n\n", student[i].kviz[j]);
                                            fseek(file, sizeof(student[i].kviz[j]), SEEK_CUR);
                                            fprintf(file, "%d", student[i].kviz[j]);
                                        }
                                    }
                                }
                            }

                        }else
                        {
                            printf("Greska !\n");
                        }
                    }while(bodovi < 0 || bodovi > 20);
                }else
                {
                    printf("Greska pri unosu !\n");
                }
            }while(unos < 0 || unos > 10);
        }else if(odabir == 0)
        {
            return -1;
        }
    }while(odabir < 0 || odabir > 1);

    fclose(file);
}

Do you have any tips what I could change, or maybe another way of doing it? I am new to this so I am open for suggestions. And the file has to remain the same (by the looks of it) I only need to be able to change 1 number in the int array kviz and write it on the place where the number was changed.

This is how the file looks like. The red mark is an example as if I wanted to change that number to 18.

Hope you understood what I wanted to say.

Also, the char s is used for user input to compare a string and display the whole structure of the student. And then I need to change from that specific student an element of int kviz



Sources

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

Source: Stack Overflow

Solution Source