In my book, it says that for a structure e.g.
x.name
is equivalent to:
x->name
however, when I tried to write a program using it, only
x->name will take in the values. I want to know why.
See below:
Code:
#include <stdio.h>
#include <stdlib.h>
struct complex {
int real;
int imaginary;
}A;
void take_values(struct complex *A)
{
printf("Please enter the real part of real number, A: \n");
scanf("%d", &(A->real));
printf("Please enter the imaginary part of complex number, B: \n");
scanf("%d", &(A->imaginary));
}
int main(void)
{
char repeat;
do{
take_values(&A);
printf("\nYou have typed %d + j%d ", A.real,A.imaginary);
printf("\nDo you want to repeat? Y/N?");
scanf(" %c", &repeat);
}while((repeat=='y')||(repeat=='Y'));
return(0);
}
However if i replace &(A->real) with &A.real, the compiler would give me something like this:
"The left hand argument of '.' must be a structure, not <ptr>complex ". Why doesn't it work? Thanks.