Brett McCoy wrote:
> On Nov 3, 2007 9:55 AM, 王德淼 <[EMAIL PROTECTED]> wrote:
> 
>> int atoi (const char *nPtr)
>>   This function change "*nPtr" into a int, and return this int.
>>
>>   For example:
>>   ---------------------------------------------------------------------
>>   #include<stdio.h>
>> #include<stdlib.h>
>>
>>   int main(){
>>  char string[6]="12345";
>>  int num[6]={0};
>>
>>    num[1] = atoi(&string[0]);
>>  num[2] = atoi(&string[1]);
>>
>>   printf("%d\n",num[1]);
>>  printf("%d\n",num[2]);
>>
>>   return 0;
>> }
>> -----------------------------------------------------------------------
>>   It's output is:
>>   ----------------------------------------
>>   12345
>>   2345
>>   --------------------------------------
>>
>>   but how can I use "atoi" to use num[1] store the first "1" and use num[2]  
>> store the "2" ?
> 
> Copy the individual elements of the string to a temp char and then
> convert, as in this example:
> 
>     int len = strlen(string);
>     char temp;
> 
>     for (int i = 0; i < len-1; i++)
>     {
>         temp = string[i];
>         num[i] = atoi(&temp);
>         ...
>      }
> 
> -- Brett
> ------------------------------------------------------------
> "In the rhythm of music a secret is hidden;
>     If I were to divulge it, it would overturn the world."
>                -- Jelaleddin Rumi

Haven't had your morning coffee yet?

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to