Help !! for typecasting char* to short array

L

LinuxGuy

Hi,
can someone pl. help me to convert character array into short
array.
actually I need in one function. but currently I have input as
character array.

Thanks
 
S

Sharad Kala

LinuxGuy said:
Hi,
can someone pl. help me to convert character array into short
array.
actually I need in one function. but currently I have input as
character array.

Can you show your attempt at it ? People here can help you better once they
know what you are trying.

Sharad
 
M

Mike Wahler

LinuxGuy said:
Hi,
can someone pl. help me to convert character array into short
array.
actually I need in one function. but currently I have input as
character array.

Your description is rather vague. I'll only guess
that you want to copy the character array's elements
to corresponding elements in the short array.

void func(const char *c, short *s, size_t count)
{
size_t i = 0;

while(i < count++)
s = c;
}

-Mike
 
H

Howard

Mike Wahler said:
Your description is rather vague. I'll only guess
that you want to copy the character array's elements
to corresponding elements in the short array.

void func(const char *c, short *s, size_t count)
{
size_t i = 0;

while(i < count++)

Did you mean...

while (i++ < count)

perhaps?


-Howard
 
M

Mike Wahler

Howard said:
Did you mean...

while (i++ < count)

perhaps?

Almost. :) What I wrote is wrong, of course, should be
something like:

while(i < count)
{
s = c;
++i;
}

Sorry for the error, 'LinuxGuy', and
thanks for pointing it out, Howard.

-Mike
 
O

Old Wolf

Mike said:
Howard said:
Did you mean...

while (i++ < count)

Almost. :) What I wrote is wrong, of course, should be
something like:

while(i < count)
{
s = c;
++i;
}


It seems there are good reasons to prefer:

std::copy(c, c + count, s);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top