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("testfile","w"
fwrite(&ab,sizeof(ABC),1,fp);
fclose(fp);
FILE *fp1;
fp1 = fopen("testfile","r"
fread(&ab,sizeof(ABC),1,fp1);
printf("Hour is %u \n",ab.hr);
printf("Number is %d \n",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
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("testfile","w"
fwrite(&ab,sizeof(ABC),1,fp);
fclose(fp);
FILE *fp1;
fp1 = fopen("testfile","r"
fread(&ab,sizeof(ABC),1,fp1);
printf("Hour is %u \n",ab.hr);
printf("Number is %d \n",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