title: How to separate an integer by comma for every three digits
body: <p>I want to input an integer, like <code>123456789</code>, and I want to output the integer like this: <code>123,456,789</code>.</p>
  
  <p>And here is my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;malloc.h&gt;
  using namespace std;
  
  char* separate(int);
  char* inttostr(int);
  int main() {
      int n;
      char* p;
      cin &gt;&gt; n;
      p = separate(n);
      cout &lt;&lt; p;
      return 1;
  }
  
  char* separate(int num) {
      char* p1, *p2 = inttostr(num), *p3, *pt;
      int count = 1;
      p1 = p2;
      while (*p2++ != '\0');
      p3 = p2 - 1;
      p2 = p2 - 2;
      while (p2 &gt; p1) {
          if (count == 3) {
              pt = p3++;
              while (pt &gt;= p2)
                  *(pt + 1) = *pt--;
              *p2 = ',';
              count = 0;
          }
          count++;
          p2--;
      }
      return p1;
  }
  
  char* inttostr(int num) {}
  </code></pre>
  
  <p>And i don't know what to do next in the <code>inttostr</code>. Can anyone can help? Thanks a lot.</p>