Alien-TinyCC
view release on metacpan or search on metacpan
src/tests/tests2/32_led.c view on Meta::CPAN
/* example from http://barnyard.syr.edu/quickies/led.c */
/* led.c: print out number as if on 7 line led display. I.e., write integer
given on command line like this:
_ _ _
| _| _| |_| |_
| |_ _| | _| etc.
We assume the terminal behaves like a classical teletype. So the top
lines of all digits have to be printed first, then the middle lines of
all digits, etc.
By Terry R. McConnell
compile: cc -o led led.c
If you just want to link in the subroutine print_led that does all the
work, compile with -DNO_MAIN, and declare the following in any source file
that uses the call:
extern void print_led(unsigned long x, char *buf);
Bug: you cannot call repeatedly to print more than one number to a line.
That would require curses or some other terminal API that allows moving the
cursor to a previous line.
*/
#include <stdlib.h>
#include <stdio.h>
#define MAX_DIGITS 32
#define NO_MAIN
/* Print the top line of the digit d into buffer.
Does not null terminate buffer. */
void topline(int d, char *p){
*p++ = ' ';
switch(d){
/* all these have _ on top line */
case 0:
case 2:
case 3:
case 5:
case 7:
case 8:
case 9:
*p++ = '_';
break;
default:
*p++=' ';
}
*p++=' ';
}
/* Print the middle line of the digit d into the buffer.
Does not null terminate. */
void midline(int d, char *p){
switch(d){
/* those that have leading | on middle line */
case 0:
case 4:
case 5:
case 6:
case 8:
case 9:
*p++='|';
break;
default:
*p++=' ';
}
switch(d){
( run in 1.343 second using v1.01-cache-2.11-cpan-acebb50784d )