L
Lingyun Yang
Dear all,
I have a file it's binary data viewed in UltraEdit is
EF BB BF 0D 0A 3C .......
I want to read them into a int or long int array byte[]
for example:
byte[0]=0xEFBB
byte[1]=0xBF0D
I write the following code, but the output isn't right:
/* ---------------code --------------- */
char dictfilename[256]="test.txt";
FILE *dictfile;
struct stat stats;
dictfile = fopen(dictfilename,"rb");
if (stat (dictfilename, &stats) == -1)
{
printf("dict file not exist!\n");
return 0;
}
int buffer[256]={1,2,3,4,5,6,7,8,9};
fread (buffer, sizeof(int), 256, dictfile);
fclose (dictfile);
for(int i=0; i<16; ++i)
printf("0xd%",buffer);
/* ---------- end of the code ---------- */
the output is :
0xd0xd0xd0xd0xd0xd0xd0xd0xd0xd0xd0xd0xd0xd0xd0xd
Is my code right?
It seems fread didn't read anything into buffer[]
Thank you for your help!
Lingyun Yang
I have a file it's binary data viewed in UltraEdit is
EF BB BF 0D 0A 3C .......
I want to read them into a int or long int array byte[]
for example:
byte[0]=0xEFBB
byte[1]=0xBF0D
I write the following code, but the output isn't right:
/* ---------------code --------------- */
char dictfilename[256]="test.txt";
FILE *dictfile;
struct stat stats;
dictfile = fopen(dictfilename,"rb");
if (stat (dictfilename, &stats) == -1)
{
printf("dict file not exist!\n");
return 0;
}
int buffer[256]={1,2,3,4,5,6,7,8,9};
fread (buffer, sizeof(int), 256, dictfile);
fclose (dictfile);
for(int i=0; i<16; ++i)
printf("0xd%",buffer);
/* ---------- end of the code ---------- */
the output is :
0xd0xd0xd0xd0xd0xd0xd0xd0xd0xd0xd0xd0xd0xd0xd0xd
Is my code right?
It seems fread didn't read anything into buffer[]
Thank you for your help!
Lingyun Yang