473,320 Members | 1,872 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,320 software developers and data experts.

Question again?

HI,
i try to read my HEX file, but i dunno why i just can read the first one in
my file ?
anyone can help me?

My code:
char c[5000000];
char d[5000000];

int main()
{

ifstream ifs;
ifs.open("opcode.txt",ios::binary);
if (ifs)
{

ifs >> c;
if
{
cout<< c <<endl;
}

else
{
cout <<"no file"<<endl;
}
~ Let us linux ~
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 22 '05 #1
7 1376
Milk wrote:
HI,
i try to read my HEX file, but i dunno why i just can read the first one in
my file ?
Read the first one what?
char c[5000000];
char d[5000000];
What happens if your file is 5 million characters long? You shouldn't
code things like this as constants. You don't use "d" in your code below.

int main()
{

ifstream ifs;
ifs.open("opcode.txt",ios::binary);
if (ifs)
{

ifs >> c;
if
What is this "if" supposed to do?
{
cout<< c <<endl;
Does your file actually contain displayable characters? If not, what do
you think this will do?
}

else
{
cout <<"no file"<<endl;
}


Count your { and }. The numbers should match. Your main says it
returns an "int" so where's your return statement?

Jul 22 '05 #2
Milk <mi*********@hotmail.com> spoke thus:
i try to read my HEX file, but i dunno why i just can read the first one in
my file ?
anyone can help me?
Possibly, if you phrased your question better... I'll add to what was
already posted, however.
char c[5000000];
char d[5000000];


1) What if your implementation doesn't like two 5 megabyte stack
buffers? Many implementations don't.
2) You want unsigned char; unadorned chars may or may not be signed,
and signed chars may not get along with binary data.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #3

"Milk" <mi*********@hotmail.com> wrote in message
news:40******@lungfunggdn.org...
HI,
i try to read my HEX file, but i dunno why i just can read the first one in my file ?
anyone can help me?

My code:
char c[5000000];
char d[5000000];

int main()
{

ifstream ifs;
ifs.open("opcode.txt",ios::binary);


We had this question fairly recently, try this

ifs.open("opcode.txt",ios::binary|ios::input);

If that fixes it then its a bug in your implementation of the standard
library.

john
Jul 22 '05 #4
>
ifs.open("opcode.txt",ios::binary|ios::input);


Sorry,

ifs.open("opcode.txt",ios::binary|ios::in);
Jul 22 '05 #5
i would like to make my program know the HEX in my input file, for example
(0x27a50004(in hex) = addu $s1, $s2, $s3)
then my program read it know 0x27a50004 after that the program will add it
for me and i need to store the s1 value register in my other array.
therefore later i can call it back and add s1 +s2 something like that~
i just dunno why if i don't have char d[5000000]; this array i just can read
the first line ~
if i have char d[5000000]; i can read second line, so did any one can teach
me??
thanks a lot
My code::
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

char c[5000000];
char d[5000000];

int main()
{

ifstream ifs;
ifs.open("opcode.txt",ios::binary);
if (ifs)
{
ifs >> c;
ifs >> d;
ifs.close();
}
else
{
cout <<"no file"<<endl;
}

cout << c << endl;
cout << d << endl;
return 0;

}
"Milk" <mi*********@hotmail.com> ¼¶¼g©ó¶l¥ó·s»D:40******@lungfunggdn.org...
HI,
i try to read my HEX file, but i dunno why i just can read the first one in my file ?
anyone can help me?

My code:
char c[5000000];
char d[5000000];

int main()
{

ifstream ifs;
ifs.open("opcode.txt",ios::binary);
if (ifs)
{

ifs >> c;
if
{
cout<< c <<endl;
}

else
{
cout <<"no file"<<endl;
}
~ Let us linux ~

~ Let us linux ~
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 22 '05 #6
Milk wrote:

HI,
i try to read my HEX file, but i dunno why i just can read the first one in
my file ?
anyone can help me?

My code:
char c[5000000];
char d[5000000];
That's not a good idea if you are dealing with truely binary data.
unsigned char is the way to go.

int main()
{

ifstream ifs;
ifs.open("opcode.txt",ios::binary);
if (ifs)
{

ifs >> c;


Since you are trying to read binary data, operator >> is not what
you want to use. Use the streams read function as in:
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
string FileName;
unsigned char c;

cout << "Enter filename: ";
cin >> FileName;

ifstream InFile( FileName.c_str(), ios::binary );

if( InFile ) {
while( InFile.read( (char*)&c, 1 ) )
cout << hex << (unsigned int)c << ' ';
}

return 0;
}
Good luck to your project.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #7

"Milk" <mi*********@hotmail.com> wrote in message
news:40******@lungfunggdn.org...
i would like to make my program know the HEX in my input file, for example (0x27a50004(in hex) = addu $s1, $s2, $s3)


You need to use read not >>.

long opcode;
ifs.read((char*)&opcode, sizeof opcode);
is for text only, not hex.


john
Jul 22 '05 #8

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

Similar topics

33
by: John Timbers | last post by:
I'd like to purchase Visual C# .Net for learning purposes only since it's a lot cheaper than Visual Studio (note that I'm a very experienced C++ developer). Can someone simply clarify the basic...
22
by: lokman | last post by:
Hi, In the following code, can someone tell me the difference between *p++ and p++ ? I can see both achieve the same result. Thanks a lot !
7
by: CT | last post by:
Hi, This might seem like a basic question but I have some doubts, please humour me. I have a client-server application using java where each client on each machine needs to directly...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
35
by: Stan Sainte-Rose | last post by:
Hi, What is the better way to save image into a database ? Just save the path into a field or save the image itself ? I have 20 000 images (~ 10/12 Ko per image ) to save. Stan
29
by: MP | last post by:
Greets, context: vb6/ado/.mdb/jet 4.0 (no access)/sql beginning learner, first database, planning stages (I think the underlying question here is whether to normalize or not to normalize this...
9
by: happyvalley | last post by:
I just wonder how to pass arguments to this function with a char** void oldmain(int argv, char**argc) { ........ } void main(void) { int argv;
20
by: fniles | last post by:
I am using VS2003 and connecting to MS Access database. When using a connection pooling (every time I open the OLEDBCONNECTION I use the exact matching connection string), 1. how can I know how...
17
by: Ben Bacarisse | last post by:
candide <toto@free.frwrites: These two statements are very different. The first one is just wrong and I am pretty sure you did not mean to suggest that. There is no object in C that is the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.