Re: viewing mbr os descriptor
- From: James Harris <james.harris.1@xxxxxxxxxxxxxx>
- Date: Sun, 18 May 2008 15:32:10 -0700 (PDT)
On 18 May, 21:57, "Bill Cunningham" <nos...@xxxxxxxxx> wrote:
"James Harris" <james.harri...@xxxxxxxxxxxxxx> wrote in message
news:c9490560-d111-44c3-9ece-c
Your printf formatting spec uses %x. That assumes the input is
unsigned int so maybe 2 but more likely 4 bytes. Check
http://linux.die.net/man/3/printf
for details including how to change the precision.
This just makes printf more complicated for me. I read the page. I don't
know if I need a length conversion or a format specifer.
I'm not a C expert and I had to run your code to find out what was
wrong. The fread call is specified thus
http://www.hmug.org/man/3/FREAD.php
If you want to use it you can see that two things are important. First
it reads what you've told it to read into a location in memory. That
is the meaning of, "storing them at the location given by ptr" in the
description. You really don't want to be using fread if you are new to
C (keep it simple) but if you use it you need to supply it the /
address/ of where the value if to be stored. C gets the address by
using "&" so if the variable is cval, say, you tell fread the address
of cval by &cval.
Second, since you've told fread to read one byte your target should be
one byte long. In C this is the char datatype. So, if you change your
fread code to
#include <stdio.h>
int main() {
char cval; //Note this uses a char
FILE *fp;
fp = fopen("b", "rb");
fread(&cval, 1, 1, fp); //Note, address of cval
fclose(fp);
printf("%x\n", cval);
return 0;
}
Don't give up on C. It's worth learning but it is pedantic so you need
to make sure you use it and its library calls correctly. If you have
further C questions check the FAQ on comp.lang.c and if you don't find
an answer ask on that group. Ignore them if they are grupmy but there
is the best group for answers to C questions.
--
HTH,
James
.
- References:
- viewing mbr os descriptor
- From: Bill Cunningham
- Re: viewing mbr os descriptor
- From: cr88192
- Re: viewing mbr os descriptor
- From: Bill Cunningham
- Re: viewing mbr os descriptor
- From: James Harris
- Re: viewing mbr os descriptor
- From: Bill Cunningham
- viewing mbr os descriptor
- Prev by Date: Re: viewing mbr os descriptor
- Next by Date: Re: spinoza programming language status report (or, disruptive technology is always late)
- Previous by thread: Re: viewing mbr os descriptor
- Next by thread: Re: viewing mbr os descriptor
- Index(es):
Relevant Pages
|