473,396 Members | 2,050 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,396 software developers and data experts.

memory reading problem in c++

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[i];
j = j + 1;
}
j = 0x7fff8;
for(i = 1; i < 17; i = i + 2)
{
ram_od[j] = mem_opcode[i];
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

May 9 '07 #1
3 1372
fazulu deen wrote:
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[i];
you're referecing mem_opcode[i]
j = j + 1;
}
j = 0x7fff8;
for(i = 1; i < 17; i = i + 2)
also here
{
ram_od[j] = mem_opcode[i];
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
May 9 '07 #2
pls suggest the mistakes made by me...yes i am refering to
mem_opcode[i] omly

May 9 '07 #3
fazulu deen wrote:
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[i];
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[i];
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?
May 10 '07 #4

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

Similar topics

2
by: assi | last post by:
Hello all We are developing a large dotnet application, which includes ~ 120 assemblies. (total size of all binaries is ~ 20MB). Our application also references the following dotnet assemblies:...
6
by: Scott Niu | last post by:
Hi, I have this following simple c++ program, it will produce memory leak ( see what I did below ). My observation also showed that: There will be a mem leak when all the 3 conditions are true:...
18
by: jacob navia | last post by:
In C, we have read-only memory (const), read/write memory (normal data), and write only memory. Let's look at the third one in more detail. Write only memory is a piece of RAM that can only...
10
by: Segfahlt | last post by:
I have a fairly simple C# program that just needs to open up a fixed width file, convert each record to tab delimited and append a field to the end of it. The input files are between 300M and...
2
by: saran | last post by:
I am having a problem with MySQL consuming a lot of memory and eventually throwing an Out of Memory error and restarting itself. The symptoms are that swap usage continues to rise until some...
8
by: Adrian | last post by:
Hi I have a JS program that runs localy (under IE6 only) on a PC but it has a memory leak (probably the known MS one!) What applications are there that I could use to look at the memory usage of...
2
by: a_agaga | last post by:
Do you know are there some reasons why many do not make processes to communicate through memory? Why network connections (sockets) are used so commonly in IPC (inter process communication)...
13
by: kolmogolov | last post by:
/* Hi, I have removed things irrelevant to reproducing the problem. What's wrong with my code? Thanks in advance for any hint! 1166425362 */ #include <stdio.h> #include <stdlib.h> #include...
6
by: itsolution | last post by:
Hi folks, Could you shed some light on this issue? my program is running on Freebsd as a daemon. When user sends a request, it forks itself and lets its child process handles the request....
10
by: deciacco | last post by:
I'm writing a command line utility to move some files. I'm dealing with thousands of files and I was wondering if anyone had any suggestions. This is what I have currently: $arrayVirtualFile =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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.