Splitting up a char into multiple ints

I am relatively new to the world of programming so I am sorry if this question is commonly asked. I have done some searching and haven't been able to figure much out.

I am trying to split up a 20 digit long char into 5 ints, each with 4 digits.

For example, my char is 01000200133700180028 and I am trying to split it up into 0100 0200 1337 0018 and 0028, each as separate ints. How would I go about doing this?



Show us your code (posted nicely in code tags). A 20 digit char, under normal circumstances would be an array of 20 char or byte in which case the answer would be array[0]...array[3], array[4]...array[7] and so on. There is no such thing as a number in Arduino that has 20 digits, that's the realm of 64bit processors.

You have your terminology slightly wrong. What you have is an array with 20 chars in it.

Perhaps the simplest way to split it up is like this (not tested)

char myCharArray[21] = {"01000200133700180028"};
char tempData[5];
int myNumbers[5];

for (byte numberCount = 0; numberCount < 5; numberCount ++) {
    for (byte charCount = 0; charCount < 4; charCount ++) {
        tempData[charCount] = myCharArray[charCount + (numberCount * 4)];
    tempData[4] = '\0';
    myNumbers[numberCount] = atoi(tempData);


Edited to correct size of myCharArray

char  data[21] = "01000200133700180028";
int result[4];

for(int i = 3; i>=0; i--) {
  data[(i+1)*5] = '\0';
  result[i] = atoi(data + (i*5));


for(int i = 3; i>=0; i--) {
  ((char (*)[5])data)[i][5] = '\0';
  result[i] = atoi(((char (*)[5])data)[i]);

Sorry all, I messed up my question.

I am using two Feather M0s with the RFM 69 Radio module to transmit and receive data. The included code is the main loop for the receiver. The data being received is of type uint8_t and named buf. When I cast the data to be of type char* and print the data, I can see that it is what I expected it to be (01000200133700180028). I hope this helps to clarify my original miscommunication.

int myData;

void loop() {

  if (rf69.available()) {
    // Should be a message for us now
    uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
    for (int i = 0; i < 2; i++) {
      if (rf69.recv(buf, &len)) {
        if (!len) return;
        buf[len] = 0;

        //myData = atoi( (char*) buf); // This doesn't work

        //Serial.print("posArray["); Serial.print(i); Serial.print("] = "); Serial.println(myData);

I hope this helps to clarify my original miscommunication.

Not really. What was your original miscommunication?