pointer to structure array

Dear people,

I have an assignment to create a pointer to an array of structures and than output it. I have 2 structures BIRTHDAY and CLIENT_RECORD. where BIRTHDAY is a part of CLIENT_RECORD.

I create a pointer of class CLIENT_RECORD and point it on the another array CLIENT_ARRAY which is equal to CLIENT_RECORD (it's part of the assignment).

But upon initialization compiler always gives me a mistake. :(

where is my problem? Can somebody give me any idea?


#include <iostream>
#include <cstring>
using namespace std;

struct BIRTHDAY{

int day;
int month;
int year;
};

struct CLIENT_RECORD{
char name[50];
char nick[20];
int age;
BIRTHDAY bday;
char gender;
};

int main(){

char reply;

do{

CLIENT_RECORD CLIENT;
struct CLIENT_RECORD* CLIENT_PTR;
CLIENT_PTR = &CLIENT;


strcpy(CLIENT.name, "Juan Dela Cruz");
strcpy(CLIENT.nick, "John");
CLIENT.age = 25;
CLIENT.bday.month = 9;
CLIENT.bday.day = 7;
CLIENT.bday.year = 1980;
CLIENT.gender = 'M';

cout<< "NAME: " << (*CLIENT_PTR).name << endl;
cout<< "NICK: " << (*CLIENT_PTR).nick << endl;
cout<< "AGE: " << (*CLIENT_PTR).age << endl;
cout<< "BIRTHDAY: " << (*CLIENT_PTR).bday.month << "/" << (*CLIENT_PTR).bday.day
<< "/" << (*CLIENT_PTR).bday.year << endl;
cout<< "GENDER: " << (*CLIENT_PTR).gender << endl;

CLIENT_RECORD CLIENT_ARRAY[5];
CLIENT_ARRAY[4] = CLIENT;


struct BIRTHDAY* B;
B = CLIENT_ARRAY[4];


cout<< endl;
cout<< "BIRTHDAY: " << (*B).month << "/" << (*B).day << "/" <<
(*B).year << endl;

cin>> reply;
}while(reply != 'n');
return 0;
}
Last edited on
You have created a pointer to BIRTHDAY structure and trying to assign it with a CLIENT_RECORD structure object. Instead you have to assign it with the BIRTHDAY structure inside CLIENT_RECORD structure.

struct BIRTHDAY* B;
B = &CLIENT_ARRAY[4].bday;


Hope this helps
Thank you Very much!!!
It really works!

Topic archived. No new replies allowed.