[ create a new paste ] login | about

Link: http://codepad.org/NMgMOMqC    [ raw code | output | fork ]

C, pasted on Mar 1:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>


 void itoa(int n, char s[]) {
     int i, sign;

     if ((sign = n) < 0)  /* record sign */
         n = -n;          /* make n positive */
     i = 0;
     do {       /* generate digits in reverse order */
         s[i++] = n % 10 + '0';   /* get next digit */
     } while ((n /= 10) > 0);     /* delete it */
     if (sign < 0)
         s[i++] = '-';
     s[i] = '\0';
     reverse(s);
 }


 /* reverse:  reverse string s in place */
 void reverse(char s[]) {
     int i, j;
     char c;

     for (i = 0, j = strlen(s)-1; i<j; i++, j--) {
         c = s[i];
         s[i] = s[j];
         s[j] = c;
     }
 }

int main() {
  char *buffer;
  itoa(INT_MIN, buffer);
  printf("%s", buffer);
  return 0;
}


Output:
1
-(


Create a new paste based on this one


Comments: