简体   繁体   中英

Null pointer assignment error in C, segmentation fault error in code

I using a old version of Borland for C lang.

At the beginning of the program you enter the name (full name, FIO ), then 4 digits (as grades). The program calculates the average among 5 entered FIO and back a average number.

#include <stdio.h>
#include <conio.h>

int main(){
    struct nya{
        char a[100];
        int x[4];
    }A[5];
    int i;
    for(i=0;i<5;i++){
        puts("FIO");
        scanf("%s", A[i].a);
        puts("4 ocenki");
        for(int g=0;g<4;g++){
        scanf("%i", A[i].x[g]);
        }
    clrscr();
    }
    float bird=0, comme[5];
    for(i=0;i<5;i++){
        comme[i]=0;

    }
    for(i=0;i<5;i++){
        for(int g=0;g<4;g++){
            comme[i]+=A[i].x[g];
        }
        comme[i]=comme[i]/4;
        bird+=comme[i];
    }
    bird=bird/5;
    printf("Sredny = %f", bird);

}

change scanf("%i", A[i].x[g]); to scanf("%i", &A[i].x[g]); (with a &)

thanks to @Blaze

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM