memory reading problem in c++

F

fazulu deen

Hi all,

pls check the following statements:

unsigned h, i=0;
FILE *fp = fopen("jump.txt","r");
if(fp)
{
while(!feof(fp))
{
fscanf(fp,"%x", &h);
mem_opcode[i++] = h;
}
}
else
printf("Can not open %s file\n","jump.txt");
}
j = 0x7fff8;
for(i = 0; i < 17; i = i + 2)
{
ram_ev[j] = mem_opcode;
j = j + 1;
}
j = 0x7fff8;
for(i = 1; i < 17; i = i + 2)
{
ram_od[j] = mem_opcode;
j = j + 1;
}
}

or example if iam having hexdata in jump file as
b8
f0
ff
8e
d8

Note:
mem_opcode[256]
ram_od[1048577]
ram_ev[1048577]
all the above are declared as two dimemsional array...
from location 7ff8 it is reading b8 ff d8.. (only even content)

wats wrong with the code....why it is not reading odd memory content

kindly give the suggestion...

regards,
fazal
 
G

Gianni Mariani

fazulu said:
Hi all,

pls check the following statements:

unsigned h, i=0;
FILE *fp = fopen("jump.txt","r");
if(fp)
{
while(!feof(fp))
{
fscanf(fp,"%x", &h);
mem_opcode[i++] = h;
}
}
else
printf("Can not open %s file\n","jump.txt");
}
j = 0x7fff8;
for(i = 0; i < 17; i = i + 2)

i increments by 2 every time
{
ram_ev[j] = mem_opcode;


you're referecing mem_opcode
j = j + 1;
}
j = 0x7fff8;
for(i = 1; i < 17; i = i + 2)

also here
{
ram_od[j] = mem_opcode;


and here ...

j = j + 1;
}
}

or example if iam having hexdata in jump file as
b8
f0
ff
8e
d8

Note:
mem_opcode[256]
ram_od[1048577]
ram_ev[1048577]
all the above are declared as two dimemsional array...
from location 7ff8 it is reading b8 ff d8.. (only even content)

wats wrong with the code....why it is not reading odd memory content

kindly give the suggestion...

regards,
fazal
 
R

Ron Natalie

fazulu said:
Hi all,

pls check the following statements:

unsigned h, i=0;
FILE *fp = fopen("jump.txt","r");
if(fp)
{
while(!feof(fp))
This is NOT the way to test for EOF. EOF is only set after
a read fails.
{
fscanf(fp,"%x", &h);
You need tot est for failure of the fscanf before blindly using it.
mem_opcode[i++] = h;
WHAT IS THE TYPE of mem_opcode?
What the hell is i?
} You want to close fp.
}
else
printf("Can not open %s file\n","jump.txt");
}
j = 0x7fff8;
for(i = 0; i < 17; i = i + 2)
i += 2 would be clearer.
Frankly I prefer that variables used solely for the loop , be declared
in the loop.
{
ram_ev[j] = mem_opcode;
j = j + 1; ++j would work here too.'
}

Hopefully the number of things filled into mem_opcode is at least 17.
j = 0x7fff8;
for(i = 1; i < 17; i = i + 2)
{
ram_od[j] = mem_opcode;
j = j + 1;
}
}

or example if iam having hexdata in jump file as
b8
f0
ff
8e
d8

Note:
mem_opcode[256]
ram_od[1048577]
ram_ev[1048577] WHAT ARE THEIR TYPES?
all the above are declared as two dimemsional array...

Huh?

Anyhow, what are you observing and why don't you think it is working?
 

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
474,294
Messages
2,571,511
Members
48,218
Latest member
NatishaFin

Latest Threads

Top