title: iOS/C: Convert "integer" into four character string
body: <p>A lot of the constants associated with Audio Session programming are really four-character strings (<a href="http://developer.apple.com/library/ios/documentation/AudioToolbox/Reference/AudioSessionServicesReference/Reference/reference.html#//apple_ref/doc/uid/TP40007915-CH6-SW2" rel="noreferrer">Audio Session Services Reference</a>). The same applies to the <a href="http://developer.apple.com/library/ios/documentation/AudioToolbox/Reference/AudioSessionServicesReference/Reference/reference.html#//apple_ref/doc/uid/TP40007915-CH7a-SW1" rel="noreferrer">OSStatus code</a> returned from functions like <code>AudioSessionGetProperty</code>.</p>
  
  <p>The problem is that when I try to print these things out of the box, they look like 1919902568. I can plug that into Calculator and turn on ASCII output and it'll tell me "roch", but there must be a programmatic way to do this.</p>
  
  <p>I've had limited success in one of my C functions with the following block:</p>
  
  <pre><code>char str[20];
  // see if it appears to be a four-character code
  *(UInt32 *) (str + 1) = CFSwapInt32HostToBig(error);
  if (isprint(str[1]) &amp;&amp; isprint(str[2]) &amp;&amp; isprint(str[3]) &amp;&amp; isprint(str[4])) {
      str[0] = str[5] = '\'';
      str[6] = '\0';
  } else {
      // no, format as integer
      sprintf(str, "%d", (int)error);
  }
  </code></pre>
  
  <p>What I want to do is to abstract this feature out of its current function, in order to use it elsewhere. I tried doing</p>
  
  <pre><code>char * fourCharCode(UInt32 code) {
      // block
  }
  void someOtherFunction(UInt32 foo){
      printf("%s\n",fourCharCode(foo));
  }
  </code></pre>
  
  <p>but that gives me "à*€/3íT:ê*€/+€/", not "roch". My C fu isn't very strong, but my hunch is that the above code tries to interpret the memory address as a string. Or perhaps there's an encoding issue? Any ideas?</p>