#include "stdio.h"
int value = 4556677;
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;  // we'll be working the buffer backwards
    *--pCurChar = '\0';   // take this out if you don't want an ASCIIZ output
                          //   but think hard before doing that...
    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 = strlen(buffer)-7;
  val2 = strlen(buffer)-6;
  val3 = strlen(buffer)-5;
  val4 = strlen(buffer)-4;
  val5 = strlen(buffer)-3;
  val6 = strlen(buffer)-2;
  val7 = strlen(buffer)-1;
  
  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", val2, val2, val3, val4, val4, val5, val6, val7);
  
  return 0;
}