The problem is while i execute my code the function modifiko_note(); doesn't work in a proper way. It execute with errors.``

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/stat.h>
#include<conio.h>

struct student{
    char emri[20];
    char mbiemri[20];
    int nota[100];
    int grupi;
}stud;

struct lendet{
    char emri[20];
    int kredite;
}lenda;

FILE *bin;
FILE *file;

void regjistro_lende();
void regjistro_student();
void regjistro_note();
void modifiko_note();
void afisho_student();
//void afisho_lende();
int nrrekordesh_lende(FILE *file);
int nrrekordesh_student(FILE *bin);

int main(){
     int zgjedhje;
     system("cls");
     printf("\n\t1.Regjistro Lendet");
     printf("\n\t2.Regjistro Studentin");
     printf("\n\t3.Regjistro Notat");
     printf("\n\t4.Korigjo Notat");
     printf("\n\t5.Shfaq rezultatet per lende");
     printf("\n\t6.Shfaq rezultatet per studente");
     printf("\n\t0.Dil");
    printf("\nMenu e zgjedhur");
    scanf("%d",&zgjedhje);

    switch(zgjedhje){
                        case 1:
                            regjistro_lende();
                            break;
                        case 2:
                            regjistro_student();
                            break;
                        case 3:
                            regjistro_note();
                            break;
                        case 4:
                            modifiko_note();
                            break; 
                        case 5:
                            afisho_student();
                            break;         
                        case 0:
                            exit(1);
                            break;
                        default:
                            printf("\n\nPerzgjidhni nje nga menu-te nga 1-6!");
                            getch();
                            main();
                            break;
                        }


}

void regjistro_lende(){
    char pergjigje;

    system("cls");
    printf("\t\tMENU 'REGJISTRIM LENDESH' ");

    file=fopen("lende.bin","ab");

    if(!file)
    printf("\n\nFile-i pati probleme ne hapje.");


    else{
        printf("\n\nJepni emrin e lendes:");
        scanf("%s",lenda.emri);
        printf("\n\nJepni kreditet e lendes");
        scanf("%d",&lenda.kredite);
        fwrite(&lenda,sizeof(struct lendet),1,file);
        fclose(file);

        printf("\n\nShtypni: \n->'p' per regjistrim te ri\n->cdo buton tjeter per tu rikthyer ne menu\n");
        scanf(" %c",&pergjigje);

        if(pergjigje=='p'||pergjigje=='P')
        regjistro_lende();
        else
        main();

    }
}


void regjistro_student(){
    char pergjigje;
    system("cls");
    printf("\t\t 'REGJISTRIM STUDENTI'");

    bin=fopen("student.bin","ab");

    if(!bin)
    printf("\n\n Skedari pati problem ne hapje");

    else {

        printf("\nEmri i studentit: \n");
        scanf("%s", &stud.emri);
        printf("\nMbiemri i studentit: \n");
        scanf("%s", &stud.mbiemri);
        printf("\nGrupi i studentit: \n");
        scanf("%d", &stud.grupi);


        fwrite(&stud,sizeof(struct student),1,bin);
        fclose(bin);

        printf("\n\nShtypni: \n->'p' per regjistrim te ri\n->cdo buton tjeter per menune kryesore");
        scanf("%c", &pergjigje);

        if (pergjigje=='p'||pergjigje=='P')
        regjistro_student ();
        else
        main();

    }
}

int nrrekordesh_lende(FILE *file){
                            struct stat st;
                            stat("lende.bin", &st);
                            int size = st.st_size;

                            return size/sizeof(struct lendet);
                            }

int nrrekordesh_student(FILE *bin){
                            struct stat st;
                            stat("student.bin", &st);
                            int size = st.st_size;

                            return size/sizeof(struct student);
                            }

void regjistro_note(){
    int i,j;
    file=fopen("lende.bin","rb");
    bin=fopen("student.bin","r+b");

    if(!file||!bin)
    printf("U ndeshen probleme ne hapje");

    else{
        int nr_lende=nrrekordesh_lende(file);
        int nr_student=nrrekordesh_student(bin);

        for(i=0;i<nr_lende;i++){
         fseek(file,sizeof(struct lendet)*i,SEEK_SET);
         fread(&lenda,sizeof(struct lendet),1,file);
         printf("\n\n\tLenda: %s",lenda.emri);
        for(j=0;j<nr_student;j++){
         fseek(bin,sizeof(struct student)*j,SEEK_SET);
         fread(&stud,sizeof(struct student),1,bin);



        printf("\nEmri: %s",stud.emri);
        printf("\nMbiemri: %s",stud.mbiemri);
        printf("\nJepni noten: ");
        scanf("%d",&stud.nota[i]);
        fwrite(&stud,sizeof(struct student),1,bin);

        }

        }
        fclose(file);    
        fclose(bin);
        main();
    }
    }

void modifiko_note(){
    char p_emri[20], p_mbiemri[20], p_lenda[20];
    char pergj,pergjigje;

    bin=fopen("student.bin","r+b");
    file=fopen("lende.bin","rb");

    if (!file&&!bin)
    printf ("Pati probleme ne hapje");

    else{
        printf("\nJepnni emrin e studentit:");
        scanf("%s", p_emri);
        printf("\nJepni mbiemrin e studentit: ");
        scanf("%s", p_mbiemri);

        int nr_student=nrrekordesh_student(bin);
        int nr_lende=nrrekordesh_lende(file);

        for (int i=0;i<nr_student;i++){
            fseek(bin,sizeof(struct student)*i, SEEK_SET);
            fread(&stud, sizeof(struct student),1,bin);


            if(strcmp(p_emri,stud.emri)==0&&strcmp(p_mbiemri,stud.mbiemri)==0)
            {
            printf("\n\n");

            printf("Emri: %s\n", stud.emri);
            printf("Mbiemri: %s\n", stud.mbiemri);
            printf("Grupi: %d\n", stud.grupi);


            printf("\nCilen lende doni te modifikoni?\n");
            scanf("%s", &p_lenda);
            printf ("Nota ekzistuese %d", stud.nota);

                int k;
                for(int j=1;j<nr_lende;j++)
                {
                    fseek(file,sizeof(struct lendet)*j, SEEK_SET);
                    fread(&lenda, sizeof(struct lendet),1,file);
                    k=j;

                    printf("\n\nVendosni noten e korigjuar");
                    scanf("%d", &stud.nota[k]);

                }
            }
        }

    fclose(file);
    fclose(bin);
}

    printf("\nShtypni p nese deshironi te beni modifikime te tjera");
    scanf("%c", &pergjigje);
    if (pergjigje=='p'||pergjigje=='P')
    modifiko_note();

    else
    main();
}


void afisho_student(){
    file=fopen("lende.bin","rb");
    bin=fopen("student.bin","rb");

    char p_emri[20],p_mbiemri[20];
    char pergjigje;

    if(!file&&!bin)
    printf("\nU hasen probleme ne hapje");

    else{
        printf("\nJepni emrin e studentint: ");
        scanf("%s",p_emri);
        printf("\nJepni mbiemrin e studentit: ");


        int nr_student=nrrekordesh_student(bin);
        int nr_lende=nrrekordesh_lende(file);
        for(int i=0;i<nr_student;i++){
            fseek(bin,sizeof(struct student)*i,SEEK_SET);
            fread(&stud,sizeof(struct student),1,bin);
            if(strcmp(p_emri,stud.emri)==0&&strcmp(p_mbiemri,stud.mbiemri==0)){
               printf("\n\n");
               printf("Emri: %s\n",stud.emri);
               printf("Mbiemri: %s\n",stud.mbiemri);
               printf("Grupi: %d\n",stud.grupi);


            for(int i=0;i<nr_lende;i++){
                fseek(file,sizeof(struct lendet)*i,SEEK_SET);
                fread(&lenda,sizeof(struct lendet),1,file);
                printf("\nLenda: ",lenda.emri);
                printf("\nNota ",stud.nota[i]);

            }   
            fclose(bin);
            fclose(file);
            }

            printf("\nShtypni p per te kerkuar nje student tjeter");
            scanf("%c",&pergjigje);
            if(pergjigje=='p'||pergjigje=='P')
            afisho_student();
            else
            main();


}
}
}   

doesn't work in a proper way. It execute with errors.

What are you expecting it to do, and what is it actually doing? What are the errors?

Please metion the error..Is it some runtime or compile time errors..If it is some run time error then plese check for the segmentation faults or if the the output is what you have desired or not. But if it has some compile error, gives us the line number. Your code is lenthy & not in English, which may create problem to find the bug if you cannot mention where to loom in your code.

This article has been dead for over six months. Start a new discussion instead.