writind hexadecimal value into a file

S

sweeet_addiction16

i have to write these hexadecimal values into a file(say using fwrite)
in c..

4d 54 68 64 00 00 00 06 00 00 00 01 00 80 4d 54 72 6b 00 00 00 8c 00
ff 58
04 04 02 30 08 00 ff 59 02 00 00 00 90 3c 28 81 00 90 3c 00 00 90 3c
1e 81
00 90 3c 00 00 90 43 2d 81 00 90 43 00 00 90 43 32 81 00 90 43 00 00
90 45
2d 81 00 90 45 00 00 90 45 32 81 00 90 45 00 00 90 43 23 82 00 90 43
00 00
90 41 32 81 00 90 41 00 00 90 41 2d 81 00 90 41 00 00 90 40 32 40 90
40 00
40 90 40 28 40 90 40 00 40 90 3e 2d 40 90 3e 00 40 90 3e 32 40 90 3e
00 40
90 3c 1e 82 00 90 3c 00 00 ff 2f 00
all these values are to be written into a file
how do i do it?
 
K

Kenneth Brody

i have to write these hexadecimal values into a file(say using fwrite)
in c..

4d 54 68 64 00 00 00 06 00 00 00 01 00 80 4d 54 72 6b 00 00 00 8c 00
ff 58 [...]
90 3c 1e 82 00 90 3c 00 00 ff 2f 00
all these values are to be written into a file
how do i do it?

I suppose this isn't what you want?

printf("4d 54 68 64 00 00 00 06 ...");

Perhaps what you are trying to say is that you have this sequence
of 8-bit values, which you have been given as a list of hexadecimal
numbers, and you need to write those out to a file?

Store them in an unsigned char array (this assumes 8-bit chars,
which is probably the case), fopen() a file (make sure to specify
binary mode), fwrite() the data, and fclose() the file.

unsigned char hexvalues[] =
{
0x4d, 0x54, 0x68, 0x64, 0x00, 0x00, 0x00, 0x06, ...
};

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
M

Marjancek

lOn said:
i have to write these hexadecimal values into a file(say using fwrite)
in c..

4d 54 68 64 00 00 00 06 00 00 00 01 00 80 4d 54 72 6b 00 00 00 8c 00
ff 58
04 04 02 30 08 00 ff 59 02 00 00 00 90 3c 28 81 00 90 3c 00 00 90 3c
1e 81
00 90 3c 00 00 90 43 2d 81 00 90 43 00 00 90 43 32 81 00 90 43 00 00
90 45
2d 81 00 90 45 00 00 90 45 32 81 00 90 45 00 00 90 43 23 82 00 90 43
00 00
90 41 32 81 00 90 41 00 00 90 41 2d 81 00 90 41 00 00 90 40 32 40 90
40 00
40 90 40 28 40 90 40 00 40 90 3e 2d 40 90 3e 00 40 90 3e 32 40 90 3e
00 40
90 3c 1e 82 00 90 3c 00 00 ff 2f 00
all these values are to be written into a file
how do i do it?

Probably you meant something like

for(int i=0; i<array_length;i++)
{
fprintf(file_hande, "%2.2X ", array;
if(i%80 == 79) fputc(file_handle, '\n');
}

Mariano.
 
W

Walter Roberson

Probably you meant something like
for(int i=0; i<array_length;i++)
{
fprintf(file_hande, "%2.2X ", array;
if(i%80 == 79) fputc(file_handle, '\n');
}


You output a newline after every 80'th array element? Not
when you reach column 80? (careful, 80 is not divisible by 3.)
 
P

psibur

i have to write these hexadecimal values into a file(say using fwrite)
in c..

4d 54 68 64 00 00 00 06 00 00 00 01 00 80 4d 54 72 6b 00 00 00 8c 00
ff 58
04 04 02 30 08 00 ff 59 02 00 00 00 90 3c 28 81 00 90 3c 00 00 90 3c
1e 81
00 90 3c 00 00 90 43 2d 81 00 90 43 00 00 90 43 32 81 00 90 43 00 00
90 45
2d 81 00 90 45 00 00 90 45 32 81 00 90 45 00 00 90 43 23 82 00 90 43
00 00
90 41 32 81 00 90 41 00 00 90 41 2d 81 00 90 41 00 00 90 40 32 40 90
40 00
40 90 40 28 40 90 40 00 40 90 3e 2d 40 90 3e 00 40 90 3e 32 40 90 3e
00 40
90 3c 1e 82 00 90 3c 00 00 ff 2f 00
all these values are to be written into a file
how do i do it?

I thought asking for help with homework problems on comp.lang.c was a
no-no. A well.

Here's a hint: Since your instructor suggested using fwrite(), either
start with either: man 3 fwrite or www.google.com and search for
fwrite().

Then do your own stinking homework.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top