Converting Char Array Loop values to integer

• 10-26-2005
azamsharp1
Converting Char Array Loop values to integer
How can I convert the Char array loop values to integers and assign to the interger array?

Code:

```// write to the procInput array                         if( atoi(processes[loop]) >= 1 && atoi(processes[loop]) <=9 )                         {                                 procInput[x] = processes[loop];                                 x++;                         }```

procInput is an integer arry and the processes is the char array

Thanks,
AzamSharp
• 10-26-2005
quzah
I'm not going to teach you how to think. You'll have to figure out how to do that on your own. You already have the answer right in front of you. Look very closely at your if check. Then go look that up, and see if you can't figure out how to do something with it.

Quzah.
• 10-26-2005
azamsharp1
Thanks I will check it out.
• 10-27-2005
SlyMaelstrom
Heh, bit of a logical error there.

A good way to do error checking in your program is to output text at various points. Put it into if statements and loops, to see what outputs and how many times.

As quzah said, look at your if statement conditions.
• 10-27-2005
azamsharp1
Hi,

Well in the documentation it says that atoi takes in character constant. Dont know what is that suppoed to mean I will do some test today and see what happens.
• 10-27-2005
rockytriton
what is processes[loop]? is it a char or a char*? If it's a char that is a number, just subtract '0' from it, if it's a char* then give it to atoi()
• 10-27-2005
azamsharp1
Hi,

well processes is a character array. like this
Code:

``` char processes[10]; for(loop = 0; loop<=10; loop++)         {                 if(processes[loop] != ',' && processes[loop] != ';')                 {                         y = processes[loop];                         printf("The value of y is %d",y);                                                 //procList[x] = processes[loop];                         //x++;                 }         }```
• 10-27-2005
rockytriton
so if process = "0,1,2,3", then to get the int value of 1 from item 2 in the array, you would say:

Code:

`int n = process[2] - '0';`
• 10-27-2005
azamsharp1
Thanks that did the trick :)