title: Is there a way to incrementally process format specifier strings in C?
body: <p>In embedded programming, I often end up with code that looks something like this:</p>
  
  <pre><code>void debug_terminal_printf(const char* format, va_list ap){
      char tmp[ARBITRARY_LIMITATION];
      vsprintf( tmp, format, ap );
      for(int pos=0; pos&lt;strlen(tmp); pos++){
          if( tmp[pos] == 0 ) break;
          uart_putc( tmp[pos] );
      }
  }
  </code></pre>
  
  <p>I want my interface to provide the convenience of string formats, but typically the consumers of the formatted string are things that consume the formatted strings a few bytes at a time, like a UART in this case. So I end up with these little temporary buffers in each of my helper functions. Use of dynamic memory is not really suitable, because decisions about the use of dynamic memory are made at the system level, and it would be inappropriate to use it in embedded platform code.</p>
  
  <p>What I <em>wish</em> to be able to do is process the string incrementally, something like this:</p>
  
  <pre><code>void debug_terminal_printf(const char* format, va_list ap){
      char tmp[MAX_TOKEN_SIZE];
      while(*format){
          int len = single_token_sprintf( tmp, format, ap );
          uart_puts(tmp);
          format += len;
      }
  }
  </code></pre>
  
  <p>This way I never need enough memory for the entire formatted string, I can wait until that hardware has consumed the last token before continuing to decode the next token.</p>
  
  <p>Has anyone ever seen a (hopefully portable) idiom like this that gets rid of the need for a large temporary buffer?</p>