Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Some guidance needed

Reply
Thread Tools

Some guidance needed

 
 
bostonmegarocker
Guest
Posts: n/a
 
      06-30-2003
Hi to all?

For the past couples of weeks I have been programming to make a
program that reads a binary file and produces the equivalent text
file.

The idea is that each byte in the file represents a temperature that
can only go from 0 to 255. So I start by reading the file in to a
character array, and the do an int casting to obtain the value of each
file, so my code is something like this:

ifstream inFile("binary.dat");
ofstream outFile("binary.txt");

inFile.seekg(0, ios::end);
int size = inFile.tellg();
inFile.seekg(0, ios::beg);
char charArray[size];

inFile.read(charArray, size);

for(int= 0; i<size; i++)
{
outFile << (int)charArray[i] <<endl;
}

.... etc ...

I expected the output to range from 0 to 255, but I get values from
-128 to 127!!? and if I use (unsigned int) instead of (int) the output
is even worst.

Is there a better way to see what is the integer equivalent that each
byte holds ?

Regards,
Alexis
_______________________
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Min
Guest
Posts: n/a
 
      06-30-2003
I assumed that 0-255 means, you don't have negative value.
Then try "unsigned char"

"bostonmegarocker" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi to all?
>
> For the past couples of weeks I have been programming to make a
> program that reads a binary file and produces the equivalent text
> file.
>
> The idea is that each byte in the file represents a temperature that
> can only go from 0 to 255. So I start by reading the file in to a
> character array, and the do an int casting to obtain the value of each
> file, so my code is something like this:
>
> ifstream inFile("binary.dat");
> ofstream outFile("binary.txt");
>
> inFile.seekg(0, ios::end);
> int size = inFile.tellg();
> inFile.seekg(0, ios::beg);
> char charArray[size];
>
> inFile.read(charArray, size);
>
> for(int= 0; i<size; i++)
> {
> outFile << (int)charArray[i] <<endl;
> }
>
> ... etc ...
>
> I expected the output to range from 0 to 255, but I get values from
> -128 to 127!!? and if I use (unsigned int) instead of (int) the output
> is even worst.
>
> Is there a better way to see what is the integer equivalent that each
> byte holds ?
>
> Regards,
> Alexis
> _______________________
> (E-Mail Removed)



 
Reply With Quote
 
 
 
 
bostonmegarocker
Guest
Posts: n/a
 
      07-01-2003
Thanks Min,
That worked for me. I really appreciate your help.
- alexis

"Min" <(E-Mail Removed)> wrote in message news:<fY0Ma.327717$(E-Mail Removed). ca>...
> I assumed that 0-255 means, you don't have negative value.
> Then try "unsigned char"
>
> "bostonmegarocker" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
> > Hi to all?
> >
> > For the past couples of weeks I have been programming to make a
> > program that reads a binary file and produces the equivalent text
> > file.
> >
> > The idea is that each byte in the file represents a temperature that
> > can only go from 0 to 255. So I start by reading the file in to a
> > character array, and the do an int casting to obtain the value of each
> > file, so my code is something like this:
> >
> > ifstream inFile("binary.dat");
> > ofstream outFile("binary.txt");
> >
> > inFile.seekg(0, ios::end);
> > int size = inFile.tellg();
> > inFile.seekg(0, ios::beg);
> > char charArray[size];
> >
> > inFile.read(charArray, size);
> >
> > for(int= 0; i<size; i++)
> > {
> > outFile << (int)charArray[i] <<endl;
> > }
> >
> > ... etc ...
> >
> > I expected the output to range from 0 to 255, but I get values from
> > -128 to 127!!? and if I use (unsigned int) instead of (int) the output
> > is even worst.
> >
> > Is there a better way to see what is the integer equivalent that each
> > byte holds ?
> >
> > Regards,
> > Alexis
> > _______________________
> > (E-Mail Removed)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Guidance needed ref. posting mp3 files please cu@thebar.com Computer Support 2 08-01-2006 09:12 PM
Guidance needed from java gurus new Java 5 07-20-2006 03:45 PM
Valuable Guidance needed for VoIP(SIP) implementation. SIP3261 VOIP 7 01-01-2005 03:54 PM
Guidance Needed for MCSD .net exam Kishor Jadhav MCSD 1 02-11-2004 09:12 AM
Guidance from classic ASP to ASP.NET help needed jm ASP .Net 3 01-21-2004 01:53 PM



Advertisments