You can calculate individual numbers using the following technique (but it does not convert them to the whole number):
Note. I use the int iteration loop to make it readable. Usually you just increment the char pointer:
void PrintInts(const char Arr[]) { int Iter = 0; while(Arr[Iter]) { if( (Arr[Iter] >= '0') && (Arr[Iter]) <= '9') { printf("Arr[%d] is: %d",Iter, (Arr[Iter]-'0') ); } } return; }
The above converts the ASCII number back to int, subtracting the smallest ASCII representation of set 0-9. So, if, for example, β0β was represented by 40 (this is not so), and β1β was represented by 41 (this is not so), 41-40 = 1.
To get the results you want, you want to use strtok and atoi:
//Assumes Numbers has enough space allocated for this int PrintInts(const int Numbers[] const char Arr[]) { char *C_Ptr = strtok(Arr," "); int Iter = 0; while(C_Ptr != NULL) { Numbers[Iter] = atoi(C_Ptr); Iter++; C_Ptr = strtok(NULL," "); } return (Iter-1); //Returns how many numbers were input }
source share