Could someone please help me with this? Why is yearofstart value not printed out in the first argument ? I knw there is something wrong, but I don't knw what is it :)
Thanks so much.

#include <stdio.h>

struct date{
int year;
}yearofstart={1950};

struct record{
char *name;
char acct_type;
struct date yearofstart;
}customer={"Jones",'A'};

void adjust(struct record *ptr);
int main(){

printf("%s %c %d \n",customer.name,customer.acct_type,customer.yearofstart.year);

adjust(&customer);

printf("%s %c %d \n",customer.name,customer.acct_type,customer.yearofstart.year);
return 0;
}

void adjust(struct record *ptr){

ptr->name="Mike";
ptr->acct_type='B';
ptr->yearofstart.year=1999;
}

The yearofstart member of struct customer variable does not bear a relation to struct yearofstart variable. You don't initialize this last (of struct date type) member of customer. It's a global variable so all its members initialized with 0.

could u please give me some more hints :(
thanks.

It's because of the scope of yearofstart declared inside the struct record lies only within that structure. If you want your program to print 1950, do this:

struct record{
char *name;
char acct_type;
struct date yearofstart;
}customer={"Jones",'A',1950};

Or do this:

printf("%s %c %d \n",customer.name,customer.acct_type,yearofstart.year);

Thanks so much, now i got it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.