cstruct

How do I read values into a structure using pointers?


I know when I have to print I use p->real and so on but what should I write when I am reading numbers using scanf?

#include <stdio.h>

typedef struct {
    int real;
    int imaginary;
} complex;

void read(complex*);

void main() {
    complex c;
    read(&c);
}    

void read(complex* p){
    /*what to write in scanf*/
}

Solution

  • You can write:

    scanf("%d %d", &p->real, &p->imaginary);
    

    but that depends heavily on the format in which the numbers come.