TechnologY

C: difference between . and ->

typedef struct {
float n_adults; float n_kids;
char day[10]; char weather[10];
} daydata ;
daydata record[30];
daydata * current;

/*

. is the member of a structure

-> is the member of a POINTED TO structure

so the next two lines mean exactly the same thing!
current->n_adults = atof(item);
(*current).n_adults = atof(item);

*/

item = strtok(lyne,” “);
current->n_adults = atof(item);

item = strtok(NULL,” “);
(*current).n_kids = atof(item);

item = strtok(NULL,” “);
strcpy((*current).day,item);

item = strtok(NULL,”\n”);
strcpy(current->weather,item);

printf(“%s\n”,(*current).day);
reccount++;

printf(“Weather Record\n”);
for (k=0; k<reccount; k++)
{
printf(“It is %s\n”,record[k].weather);
printf(“Adults: %f\n”,record[k].n_adults);
}

Reference: http://www.wellho.net/resources/ex.php4?item=c209/dinners.c

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s