Q:

va_arg returns only parts of my integer

I am trying to write my own va_args functions for the first time and I am having a problem that large integers (still within the range of int) are getting truncated to 3 digits, and out of order!
Here is the implementation

void __sprintf(char * _string, ...)
{
  int i = a_sizeof(_string); char _arg; int j =0; int format = 0;
  va_list args;
  va_start (args,_string);
  for(; j < i; j++)
  {
    if(_string[j] == '\0')
      break;
    else if(_string[j] == '%')
    {
      format=1;
      continue;
    }
    else if(format==1)
    {   
      switch(_string[j])
      {
      case 'd':
        _arg = va_arg(args,int);
        printi(_arg);  //Prints integers over serial by converting to ASCII
        break;

      default:
        continue;

      }
      format = 0;
    }
    else
      SerialPutChar(_string[j]);
  }
  va_end(args);

}

What I get when I try __sprintf("%d %d %d\n",32141,6400,919911); is  141 32 then it exits. I have set break points and sometimes it looks like Im getting total crap passed.
Suspicions:
IAR's implementation of stdarg
complete bone-head miss-use of va_arg
missing fine-print details (which are probably in bold 14pt but no one reads it anyway)
Thanks in advance!

A:

You have declared char _arg instead of int _arg, therefore the "truncation"
of the integer values.

