Question again?



 DEVELOP > c-Plus-Plus > Question again?

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Milk"
Date: 13 Apr 2004 08:31:02 AM
Object: 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! =-----
.

User: "John Harrison"

Title: Re: Question again? 13 Apr 2004 10:56:33 AM
"Milk" <milkmilk776@hotmail.com> wrote in message
news:407cbe86@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
.
User: "John Harrison"

Title: Re: Question again? 13 Apr 2004 11:10:41 AM


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

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


User: "Christopher Benson-Manica"

Title: Re: Question again? 13 Apr 2004 09:23:24 AM
Milk <milkmilk776@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.
.

User: "Karl Heinz Buchegger"

Title: Re: Question again? 13 Apr 2004 01:02:56 PM
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
kbuchegg@gascad.at
.

User: "Bill Seurer"

Title: Re: Question again? 13 Apr 2004 08:41:39 AM
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?
.

User: "Milk"

Title: Re: Question again? 13 Apr 2004 11:49:27 AM
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" <milkmilk776@hotmail.com> ¼¶¼g©ó¶l¥ó·s»D:407cbe86@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! =-----
.
User: "John Harrison"

Title: Re: Question again? 14 Apr 2004 05:22:01 AM
"Milk" <milkmilk776@hotmail.com> wrote in message
news:407ced07@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
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER