473,408 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

writind hexadecimal value into a file

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?

Aug 30 '07 #1
4 2104
sw****************@yahoo.com wrote:
>
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:Th*************@gmail.com>

Aug 30 '07 #2
lOn Aug 30, 6:01 pm, sweeet_addictio...@yahoo.com wrote:
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[i];
if(i%80 == 79) fputc(file_handle, '\n');
}

Mariano.

Aug 31 '07 #3
In article <11**********************@x40g2000prg.googlegroups .com>,
Marjancek <ma*******@gmail.comwrote:
>lOn Aug 30, 6:01 pm, sweeet_addictio...@yahoo.com wrote:
>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
>Probably you meant something like
>for(int i=0; i<array_length;i++)
{
fprintf(file_hande, "%2.2X ", array[i];
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.)
--
Programming is what happens while you're busy making other plans.
Aug 31 '07 #4
On Aug 30, 12:01 pm, sweeet_addictio...@yahoo.com wrote:
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.

Aug 31 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: pavithra.eswaran | last post by:
Hi, I would like to convert a single precision hexadecimal number to floating point. The following program seems to work fine.. But I do not want to use scanf. I already have a 32 bit hexadecimal...
5
by: Damon | last post by:
I'm getting '', hexadecimal value 0x02, is an invalid character when I'm deseralizing XML from a 3rd party XML gateway. How do I get rid of these hexadecimal values before I deserialize? Cheers...
2
by: Pushpendra | last post by:
I am storing the encrypted password in xml file which I have saved in unicode format. While I try to read the xml file and create a dataset from it, it shows me the following error ...
15
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
8
by: Vijay | last post by:
Hi , I am doing a small project in c. I have a Hexadecimal file and want to convert into ascii value. (i.e., Hexadecimal to Ascii conversion from a file). Could anyone help me? Thanks in...
7
by: elliotng.ee | last post by:
I have a text file that contains a header 32-bit binary. For example, the text file could be: %%This is the input text %%test.txt Date: Tue Dec 26 14:03:35 2006...
5
by: Just D | last post by:
All, Any valuable idea about subj: "The '%' character, hexadecimal value 0x25" ? I tried to google, but nothing interesting was found. Is it IIS settings problem, user side problem or...
6
by: Andrea | last post by:
Hi, suppose that I have a string that is an hexadecimal number, in order to print this string I have to do: void print_hex(unsigned char *bs, unsigned int n){ int i; for (i=0;i<n;i++){...
8
by: scad | last post by:
I have a file that has blocks of data that can vary in length. The first 2 bytes of the block are a Hex number telling me how many bytes long the block is (including those 2 bytes). I need to be...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.