David Demers

CAST a CHAR array as a structure

Discussion created by David Demers on Mar 20, 2008
Latest reply on Apr 14, 2008 by David Demers
i have the following struct code
 
struct record
{
 char Name[21];
 char date[3];
};
 
 char array[24];
 char *ptr=array;
 
 struct record *read_record;
 
 array[0]=1;
 array[1]=2;

 read_record = (struct record*) ptr;
 
printf(" %c %c\n",read_record->Name[0],read_record->Name[1] );
 
this should display 1 and 2, but display nothing.   
 
can anyone expalin what i'm doing wrong?
thanks
 
 return 0;

Outcomes