C function to return byte array from signed short array in linux

I need an example of a function to take a signed sort array and return a byte array written in C for Linux.  I'm new to C and need and need an explicit example please.
StarDusterIIAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Infinity08Commented:
Depending on the purpose, you can simply cast a pointer to signed short to a pointer to unsigned char :

        short array[SIZE];
        unsigned char* bytes = (unsigned char*) array;

It depends on what this will be used for though. Maybe you can give a bit more background information about what this is for ?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
StarDusterIIAuthor Commented:
It's for an audio routine.  Input to the audio conversion routine needs a byte array and the output from the input source is a short array.
0
Infinity08Commented:
Ok, and what does the documentation say about the format of both arrays ?
0
StarDusterIIAuthor Commented:
Documentation??  How funny!!   ;-)

Your suggestion actually worked but I have an endian problem.  Anyway to change  the order of bytes in the short array so they come out reversed?
0
Infinity08Commented:
>> Your suggestion actually worked but I have an endian problem.

Which is what the documentation should have showed : the expected byte order.

If there's no (proper) documentation, then the API you're using is more difficult to use correctly (and might involve trial and error).


>> Anyway to change  the order of bytes in the short array so they come out reversed?

Assuming that a short on your system is 2 bytes, you could swap around every pair of bytes in the byte array.
Or you could use htons for that :

        http://linux.die.net/man/3/htons
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.