#include "stdio.h"
int value = 7722331;
int val;
int val1;
int val2;
int val3;
int val4;
int val5;
int val6;
int val7;

void uint_to_str_leading( char* dst, unsigned int i, size_t size )
{
    char* pCurChar;
    if (size == 0) return;
    pCurChar = dst + size;
    *--pCurChar = '\0';
    while (pCurChar != dst) {        
        int digit = i % 10;
        i = i /10;
        *--pCurChar = '0' + digit;
    }
    return;
}

void int_to_str_leading( char* dst, int i, size_t size )
{
    if (size && (i < 0)) {
        *dst++ = '-';
        size -= 1;
        i *= -1;
    }
    uint_to_str_leading( dst, i, size);
    return;
}

int main(void) {
  char buffer[80];
  char str[20];
  uint_to_str_leading(buffer, value, 8); 
  strcpy(str, buffer);
  val = atoi(str);
  
  printf("Sensor: %d\n", value);
  
  printf("\n");
  
  printf("1st digit: %.1s\n", buffer);
  printf("2-3st digits: %.2s\n", &(buffer[strlen(buffer)-6]));
  printf("4-5st digits: %.2s\n", &(buffer[strlen(buffer)-4]));
  printf("6-7st digits: %s\n", &(buffer[strlen(buffer)-2]));
  
  val1 = (buffer[strlen(buffer)-7])-48;
  val2 = (buffer[strlen(buffer)-6])-48;
  val3 = (buffer[strlen(buffer)-5])-48;
  val4 = (buffer[strlen(buffer)-4])-48;
  val5 = (buffer[strlen(buffer)-3])-48;
  val6 = (buffer[strlen(buffer)-2])-48;
  val7 = (buffer[strlen(buffer)-1])-48;
  
  printf("\n");
  
  printf("String: %s\n", buffer);
  printf("Value(int): %07d\n", val);
  
  printf("\n");
  
  printf("Vals : %d %d %d %d %d %d %d\n", val1, val2, val3, val4, val5, val6, val7);
  
  return 0;
}