Reverse endianizer in C++

Post here about scripting and programming for HaloPC (audio, network, ai, etc.)
Post Reply
MadCactus





Posts: 29
Joined: Mon Jun 07, 2004 1:59 pm
Location: Colorado

Reverse endianizer in C++

Post by MadCactus »

Well, my basic plan of attack was to just make an array that read in the data (4 bytes at a time) and wrote it to file backwards (4 bytes at a time). Here is the source code so far:
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <stddef.h>

int main()
{
ifstream in_stream;
ofstream out_stream;

in_stream.open("infile.dat");

unsigned char byte[4];

in_stream >> byte[0] >> byte[1] >> byte[2] >> byte[3];

out_stream.open("midfile.dat");

out_stream << byte[3] << byte[2] << byte[1] << byte[0];

return 0;

}
It reverses them, but it skips over any whitespace it may encounter (such as byte 20 in ASCII). Also, I don't know how to jump ahead 4 bytes after writing them each time. I am a bit of a C++ n00b so help would be fantastico.[/quote]
kaptainkommie




Wordewatician 500

Posts: 732
Joined: Wed Nov 26, 2003 11:59 pm
Location: Raleigh, NC, USA

Post by kaptainkommie »

MadCactus





Posts: 29
Joined: Mon Jun 07, 2004 1:59 pm
Location: Colorado

Post by MadCactus »

sweet

i did google but found little.
User avatar
Edwin





Posts: 1111
Joined: Mon Nov 24, 2003 7:24 pm
Location: Z'ha'dum

Post by Edwin »

kaptainkommie wrote:http://www.cplusplus.com/doc/tutorial/tut6-1.html

Google for tutorials....
FWOOSH!!!! way over my head. i need to take a c++ course or something..... the encoder looks good so-far though.
"If you go to Z'ha'dum you will die."
DiablodeMorte





Posts: 21
Joined: Wed Dec 10, 2003 3:01 am

Post by DiablodeMorte »

I wouldn't encode it that way...I would take a password(like bob) then convert it into ascii then ADD it to the ascii version of the text that u want to be encoded...To decode just subtract the password from what you get...Easy?...

Tried to help..
-Roan
kaptainkommie




Wordewatician 500

Posts: 732
Joined: Wed Nov 26, 2003 11:59 pm
Location: Raleigh, NC, USA

Post by kaptainkommie »

Um, your little method has not a DAMN thing to do with what he's trying to do.
Post Reply