[ create a new paste ] login | about

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

EnzoFerber - C, pasted on Jan 18:
#include <stdio.h>
#include <string.h>
#include <unistd.h>

char *buildnum ( int number, int n, char pad )
{
   char *str = (char *)malloc((n+1)*sizeof(char)), *a = str;

   a[n] = 0x0;
   
   while ( (number) && (*(a++) = (number%10) + 48) ) (number /= 10) ;
   while ( *a ) *(a++) = pad;
   
   return str;
}

int main ( void )
{
   printf ( "%s\n", buildnum(99,3,'0'));
   printf ( "%s\n", buildnum(99,9,'0'));
   return 0;
}


Output:
1
2
990
990000000


Create a new paste based on this one


Comments: