Fehler: - Ausdruck muss struct-oder union-Typ in c

Ich habe einen code zum speichern von Namen und Noten der Studierenden, dann erinnern Sie die Klasse, als die Schüler die Namen eingetragen sind.

Hier ist mein code:

#include <stdio.h>

#define N 10
#define M 2

struct a
{
     char name[50];
     int grade;
};

int main()
{
    int i;
    int j;
    struct a A[N][M];

    for(i=0;i<N;i++)
    {
         printf("Please Enter Students' Names:/n");
            scanf("%s", &A[i].name);
    }
    for(j=0;j<M;j++)
    {
        printf("Please Enter Students' Grades:/n");
            scanf("%d", &A[j].grade);
    }
    printf("Which Student's Grades Would You Like To View?/n");
        if(scanf("%s", *A[i].name))
        {
            printf("Their Grade Is:%d/n", *A[j].grade);
        }
    return 0;
}

Ich habe immer diesen Fehler:

hw2problem2.c(21): error: expression must have struct or union type
                        scanf("%s", &A[i].name);
                                     ^
hw2problem2.c(26): error: expression must have struct or union type
                        scanf("%d", &A[j].grade);
                                     ^
hw2problem2.c(29): error: expression must have struct or union type
                if(scanf("%s", *A[i].name))
                                ^
hw2problem2.c(31): error: expression must have struct or union type
                        printf("Their Grade Is:%d/n", *A[j].grade);
                                                       ^
compilation aborted for hw2problem2.c (code 2)

Jede Hilfe bei der Fehler oder das Programm im Allgemeinen würde geschätzt werden.
Danke.

Warum ein 2D-array?

InformationsquelleAutor proflavahot | 2014-10-09

Schreibe einen Kommentar