Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

print integer to stdout using write or putchar?

#include "my_putchar.h"
/* 0x2D = '-'
 * 0x0 = NUL */
int my_put_nbr(int n)
{
        if (n < 0)
        {
                my_putchar(0x2D);
                n = -n;
        }

        if (n > 9)
        {
                my_put_nbr(n/10);
        }

        my_putchar((n%10) + '0');

        return 0;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #print #integer #stdout #write
ADD COMMENT
Topic
Name
9+2 =