Little Endian to Big Endian

I am attempting to load a file type that is always encoded as little endian. I have all the code for opening the file type and taking the data in done, I just need to know how I should go about converting the endianess of said data. Apparently, converting it to "Host" format, can do this, but only sometimes, so that's not the greatest solution. I found this code on a forum:

I'm not sure how it works, except that it can convert unsigned shorts and ints. Which I need, so if that works, good, but I also need to be able to read char[] data from the file. What kind of routine would I use in that case? And do I convert the data *after* it's read from the file? (Into designated structs.)

Also, does this process cause a big performance drop, usually? If it does, I'll just right a program for taking all my games data, and cycling it to big endian before hand. (Before distributing the game, for example.)

There are two ways to read in char arrays from what I know, although it depends on how it's being stored in the file:

1) Each "string" in the file has a short or long specifying the length of the string, then you just read in that many chars. If you need this method, make sure you byte-swap the length of the string of course!
2) If the file does not have a length specified, odds are it just loops by reading in one char at a time until it hits the null character.

Swapping endianness is very quick, so don't bother creating new data files for everything.

And finally, storing the raw data into structs depends entirely on the format of the file and your implementation of the data structures, so I can't really answer that.

Thanks for your help, OneSadCookie and mikedaman, your help has clarified things greatly. Is there any way of checking the endianess of the system by code is running on? (If I wanted to make a universal binary for PPC and x86 macs, or I wanted my code to be completely window/mac compile compatible.)

PS: Perhaps a silly question, but the 64bit-dness of some processors won't affect endianess in any way, would it?

64 bit computers are the same as 32 bit as far as endianness is concerned.

Thanks! I actually found that same source within a couple of minutes of searching. Should've googled first.

OneSadCookie mentioned that char's are one byte, so no byte ordering problem. But what If I'm reading a set of chars of unknown length, into an array. Would the word "hello" be stored (figuratively) as "olleh" if read on the wrong endianess of machine. Then again, ever item in the array would not actually become an array until it is loaded onto the memory stack anyway, correct?

EDIT: What if I need to swap... *gasp* a float? (That decimal point must thrown in a complication... *quakes in fear*).

To swap floats, you can do a cast such as this:
*(unsigned int *)&myFloat
and then swap it as you would an unsigned int. I've had no problems with floats, since they are an IEEE standard. To answer your other question, the only time you need to swap the bytes are if each individual piece of data is > 1 byte. For example, if you have an array, you count each element separately. If you have a string, each element is only 1 byte, so no swapping is necessary. I've you have an array of shorts, ints, floats, etc. you will need to swap each individual item accordingly.

You mean... declare the same function, but in one if it's with a conversion, and the other it isn't? Why? That just makes the code harder to read for n00bs like me with no understanding of such things.