0

when I execute the following code I get an error message for this line scanf("%s",A.(T+i)->CNE)

error message : expected identifier before '(' token|

can I know what is the problem? thanks in advance.

typedef struct date
{
    int day;
    int month;
    int year;
}date;
typedef struct Student
{
    char CNE[10];
    char FirstName[30];
    char LastName[30];
    date BD;
    float Grades[6];
}Student;
typedef struct Class
{
    Student T[1500];
    int dim;
}Class;
Class input(Class A)
{
    int i=A.dim;
    printf("Enter the student CNE : ");
    scanf("%s",A.(T+i)->CNE);
}
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
LEARNER
  • 123
  • 1
  • 9

3 Answers3

1

(T+i) is not a member of the structure Class, so you cannot use A.(T+i).

It seems A.(T+i)->CNE should be A.T[i].CNE.

Also it is suspicious that the modified A is discarded at returning from the function input. It seems you forgot to write return A;.

MikeCAT
  • 73,922
  • 11
  • 45
  • 70
1

The only thing that can be after a . operator is a member name. It cannot be an expression such as (T+i).

Normally, to access element i of the member T, one would use A.T[i], and then its CNE member would be A.T[i].CNE.

Presumably, you have been studying pointer arithmetic and are interested in accessing A.T[i] using pointers. In this case, A.T + i will give the address of element i of A.T. Then (A.T + i)->CNE will be the CNE member of that element. (Observe that A.T is an array, but, in this expression, it is automatically converted to a pointer to its first element. So A.T + i is equivalent to &A.T[0] + i, which says to take the address of A.T[0] and advance it by i elements.)

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312
1

It seems you mean either

scanf("%s",A.T[i].CNE);

or

scanf("%s", ( A.T + i )->CNE );

That is in the used by you expression

A.(T+i)->CNE

the dot operator expects an identifier instead of an expression.

And your function return nothing though its return type is not void.

The function could be declared and defined for example the following way

void input(Class *A)
{
    int i = A->dim;
    printf("Enter the student CNE : ");
    scanf( "%s", ( A->T + i )->CNE );
}
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335