extracting characters from array in C

Thread Starter

Michel_e_r

Joined May 30, 2008
11
Hello,

I'm trying to retrieve characters stored into an array and move them into a variable. For instance:

char array[]="1,2,3,4";

to be stored in a char variable so it ends up like this

value = 1234

how can I accomplish this?

thank you.
 

RiJoRI

Joined Aug 15, 2007
536
Zero out value.
Scan the array. If the character is numeric, multiply value by 10 and add the de-ASCII'd character. Repeat until done. Show us what you have accomplished.

--Rich
 

rjenkins

Joined Nov 6, 2005
1,013
I'm puzzled here..
You say you want to put the result in a char variable?

A single char is generally an unsigned byte, range 0-255 so I can only guess you mean a character string variable, which is actually a character array in C, as you started with?
 

RiJoRI

Joined Aug 15, 2007
536
I'm puzzled here..
You say you want to put the result in a char variable?

A single char is generally an unsigned byte, range 0-255 so I can only guess you mean a character string variable, which is actually a character array in C, as you started with?
The type of value was not defined by the OP, who is trying to convert a series of chars in an array into a number. (How the commas get in there has me puzzled...)

And do NOT assume what a char is. I have seen as many compilers declare chars as "signed" as "unsigned."

--Rich
 
Top