Code:
#include <stdio.h>
#include <stdlib.h>
void sevenSegmentDisplay(int userInput);
const char segments[10][3][3] =
{
{{' ', '_', ' '}, {'|', ' ', '|'}, {'|', '_', '|'}}, //0
{{' ', ' ', ' '}, {' ', ' ', '|'}, {' ', ' ', '|'}}, //1
{{' ', '_', ' '}, {' ', '_', '|'}, {'|', '_', ' '}}, //2
{{' ', '_', ' '}, {' ', '_', '|'}, {' ', '_', '|'}}, //3
{{' ', ' ', ' '}, {'|', '_', '|'}, {' ', ' ', '|'}}, //4
{{' ', '_', ' '}, {'|', '_', ' '}, {' ', '_', '|'}}, //5
{{' ', '_', ' '}, {'|', '_', ' '}, {'|', '_', '|'}}, //6
{{' ', '_', ' '}, {' ', ' ', '|'}, {' ', ' ', '|'}}, //7
{{' ', '_', ' '}, {'|', '_', '|'}, {'|', '_', '|'}}, //8
{{' ', '_', ' '}, {'|', '_', '|'}, {' ', '_', '|'}}, //9
};
int main(void)
{
int a;
sevenSegmentDisplay(a);
return 0;
}
void sevenSegmentDisplay(int userInput)
{
int i, j;
printf("Please enter a number: ");
userInput = getchar();
if(userInput == '-')
{
// print a negative sign
}
while(userInput != '\n')
{
userInput = userInput - '0';
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
printf("%c", segments[userInput][i][j]);
}
putchar('\n');
}
userInput = getchar();
}
}
Currently, my code will read in the user input and print each number individually, with newlines in between each one.