|
-
February 18th, 2004, 03:20 PM
#1
fscanf issues (final question)
im a bit confused by the following action
say i have a file
/////////////////////////////
20
34 04422886
/////////////////////////////
if i read this file using the following code
while(fgets(buff,95,infile)) {
sscanf(buff,"%x %x",&memAddress,&memContents);
if(memContents == -1){
/* code to skip first line */
}
else{
memAdd[i] = memAddress;
memCont[i] = memContents;
}
*note* i do have other error checking within this
block i reduced it to the most basic read stuff for posting
where memAddr should be 34
and memContents should be 04422886
and i do the folllowing
printf("memContents = %x\n", memCont[i]);
my output is
memContents = 4422886
what happened to the 0 that began the hexidecimal number
-
February 18th, 2004, 06:14 PM
#2
It is just like with any other bases (position system)... leading zeros don't count, ie 00ff == ff.
-
February 19th, 2004, 02:12 PM
#3
If you're printing out a 32-bit hex number, do this:
printf("0x%08x", theHexNumber);
For 003abcde, will print:
0x003abcde
Use capital X if you want capital hex letters. FYI, with the 08 in the formatting spec, the 0 tells it to pad using "0", and the 8 tells it to output, minimum, 8 characters. Also, the leading "0x" is just pretty print. You can leave it out of the formatting spec if you like.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|