Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading a structure

Status
Not open for further replies.

sajiv77

Programmer
Joined
Jan 2, 2002
Messages
14
Location
IN
Please see this file .I shall tell the problem.
Compile it if on Linux with
g++ FileName.cpp


include <stdio.h>
#define WRD 2
typedef unsigned char byte;
typedef struct
{
byte hr;
byte trans_no[WRD];
} ABC;

main()
{
ABC ab;
ab.hr=10;
*(int *)ab.trans_no=20;

FILE *fp;
fp = fopen(&quot;testfile&quot;,&quot;w&quot;);
fwrite(&ab,sizeof(ABC),1,fp);
fclose(fp);

FILE *fp1;
fp1 = fopen(&quot;testfile&quot;,&quot;r&quot;);
fread(&ab,sizeof(ABC),1,fp1);
printf(&quot;Hour is %u \n&quot;,ab.hr);
printf(&quot;Number is %d \n&quot;,ab.trans_no);
fclose(fp1);
}

How do i get the correct value for the trans_no.
Also how do i assign values for the array type variable

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top