Alien-TinyCCx
view release on metacpan or search on metacpan
src/tests/tests2/32_led.c view on Meta::CPAN
/* extract digits from x */
n = ( x == 0L ? 1 : 0 ); /* 0 is a digit, hence a special case */
while(x){
d[n++] = (int)(x%10L);
if(n >= MAX_DIGITS)break;
x = x/10L;
}
/* print top lines of all digits */
for(i=n-1;i>=0;i--){
topline(d[i],buf);
buf += 3;
*buf++=' ';
}
*buf++='\n'; /* move teletype to next line */
/* print middle lines of all digits */
for(i=n-1;i>=0;i--){
midline(d[i],buf);
buf += 3;
*buf++=' ';
}
*buf++='\n';
/* print bottom lines of all digits */
for(i=n-1;i>=0;i--){
botline(d[i],buf);
buf += 3;
*buf++=' ';
}
*buf++='\n';
*buf='\0';
}
int main()
{
char buf[5*MAX_DIGITS];
print_led(1234567, buf);
printf("%s\n",buf);
return 0;
}
#ifndef NO_MAIN
int main(int argc, char **argv)
{
int i=0,n;
long x;
static int d[MAX_DIGITS];
char buf[5*MAX_DIGITS];
if(argc != 2){
fprintf(stderr,"led: usage: led integer\n");
return 1;
}
/* fetch argument from command line */
x = atol(argv[1]);
/* sanity check */
if(x<0){
fprintf(stderr,"led: %d must be non-negative\n",x);
return 1;
}
print_led(x,buf);
printf("%s\n",buf);
return 0;
}
#endif
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
( run in 1.629 second using v1.01-cache-2.11-cpan-5b529ec07f3 )