473,387 Members | 1,517 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,387 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 1377
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.