Приведенный ниже код должен принимать вход, сохранять его, а затем отображать светодиоды, которые дают номер в качестве дисплея.Однако это дает случайные светодиоды, а не правильный.Я проверил несколько вещей, но я не вижу, что не так, вы можете помочь?
#include <stdio.h>
int main( void )
{
/* Declare a data variable for each pixel. */
int a1, a2, a3, a4, a5 =0;
int b1, b2, b3, b4, b5 =0;
int c1, c2, c3, c4, c5 =0;
int d1, d2, d3, d4, d5 =0;
int e1, e2, e3, e4, e5 =0;
int f1, f2, f3, f4, f5 =0;
int g1, g2, g3, g4, g5 =0;
int h1, h2, h3, h4, h5 =0;
int i1, i2, i3, i4, i5 =0;
int j1, j2, j3, j4, j5 =0;
int k1, k2, k3, k4, k5 =0;
int l1, l2, l3, l4, l5 =0;
/* Collect the data from stdin and store in a string */
char str[6];
scanf("%s", str);
int a = str[0] - '0';
int b = str[1] - '0';
int c = str[2] - '0';
int d = str[3] - '0';
/* Change the pixels to store the shape of the numbers to be displayed */
switch ( a ) {
case 0:
a1, b1, c1, a2, c2, a3, c3, a4, c4, a5, b5, c5 = 1;
break;
case 1:
c1, c2, c3, c4, c5 = 1;
break;
case 2:
a1, b1, c1, c2, a3, b3, c3, a4, a5, b5, c5 = 1;
break;
case 3:
a1, b1, c1, c2, a3, b3, c3, c4, a5, b5, c5 = 1;
break;
case 4:
a1, c1, a2, c2, a3, b3, c3, b4, b5 = 1;
break;
case 5:
a1, b1, c1, a2, a3, b3, c3, c4, a5, b5, c5 = 1;
break;
case 6:
a1, b1, c1, a2, a3, b3, c3, a4, c4, a5, b5, c5 = 1;
break;
case 7:
a1, b1, c1, c2, c3, c4, c5 = 1;
break;
case 8:
a1, b1, c1, a2, c2, a3, b3, c3, a4, c4, a5, b5, c5 = 1;
break;
case 9:
a1, b1, c1, a2, c2, a3, b3, c3, c4, c5 = 1;
break;
default:
printf("Please input a valid number");
return 0;
break;
}
switch ( b ) {
case 0:
d1, e1, f1, d2, f2, d3, f3, d4, f4, d5, e5, f5 = 1;
break;
case 1:
f1, f2, f3, f4, f5 = 1;
break;
case 2:
d1, e1, f1, f2, d3, e3, f3, d4, d5, e5, f5 = 1;
break;
case 3:
d1, e1, f1, f2, d3, e3, f3, f4, d5, e5, f5 = 1;
break;
case 4:
d1, f1, d2, f2, d3, e3, f3, e4, e5 = 1;
break;
case 5:
d1, e1, f1, d2, d3, e3, f3, f4, d5, e5, f5 = 1;
break;
case 6:
d1, e1, f1, d2, d3, e3, f3, d4, f4, d5, e5, f5 = 1;
break;
case 7:
d1, e1, f1, f2, f3, f4, f5 = 1;
break;
case 8:
d1, e1, f1, d2, f2, d3, e3, f3, d4, f4, d5, e5, f5 = 1;
break;
case 9:
d1, e1, f1, d2, f2, d3, e3, f3, f4, f5 = 1;
break;
default:
printf("Please input a valid number");
return 0;
break;
}
switch ( c ) {
case 0:
g1, h1, i1, g2, i2, g3, i3, g4, i4, g5, h5, i5 = 1;
break;
case 1:
i1, i2, i3, i4, i5 = 1;
break;
case 2:
g1, h1, i1, i2, g3, h3, i3, g4, g5, h5, i5 = 1;
break;
case 3:
g1, h1, i1, i2, g3, h3, i3, i4, g5, h5, i5 = 1;
break;
case 4:
g1, i1, g2, i2, g3, h3, i3, h4, h5 = 1;
break;
case 5:
g1, h1, i1, g2, g3, h3, i3, i4, g5, h5, i5 = 1;
break;
case 6:
g1, h1, i1, g2, g3, h3, i3, g4, i4, g5, h5, i5 = 1;
break;
case 7:
g1, h1, i1, i2, i3, i4, i5 = 1;
break;
case 8:
g1, h1, i1, g2, i2, g3, h3, i3, g4, i4, g5, h5, i5 = 1;
break;
case 9:
g1, h1, i1, g2, i2, g3, h3, i3, i4, i5 = 1;
break;
default:
printf("Please input a valid number");
return 0;
break;
}
switch ( d ) {
case 0:
j1, k1, l1, j2, l2, j3, l3, j4, l4, j5, k5, l5 = 1;
break;
case 1:
l1, l2, l3, l4, l5 = 1;
break;
case 2:
j1, k1, l1, l2, j3, k3, l3, j4, j5, k5, l5 = 1;
break;
case 3:
j1, k1, l1, l2, j3, k3, l3, l4, j5, k5, l5 = 1;
break;
case 4:
j1, l1, j2, l2, j3, k3, l3, k4, k5 = 1;
break;
case 5:
j1, k1, l1, j2, j3, k3, l3, l4, j5, k5, l5 = 1;
break;
case 6:
j1, k1, l1, j2, j3, k3, l3, j4, l4, j5, k5, l5 = 1;
break;
case 7:
j1, k1, l1, l2, l3, l4, l5 = 1;
break;
case 8:
j1, k1, l1, j2, l2, j3, k3, l3, j4, l4, j5, k5, l5 = 1;
break;
case 9:
j1, k1, l1, j2, l2, j3, k3, l3, l4, l5 = 1;
break;
default:
printf("Please input a valid number");
return 0;
break;
}
/* Display the pixels in the correct order */
if (a1 == 1 )
printf("O");
else
printf(" ");
if (b1 == 1 )
printf("O");
else
printf(" ");
if (c1 == 1 )
printf("O");
else
printf(" ");
if (d1 == 1 )
printf("O");
else
printf(" ");
if (e1 == 1 )
printf("O");
else
printf(" ");
if (f1 == 1 )
printf("O");
else
printf(" ");
if (g1 == 1 )
printf("O");
else
printf(" ");
if (h1 == 1 )
printf("O");
else
printf(" ");
if (i1 == 1 )
printf("O");
else
printf(" ");
if (j1 == 1 )
printf("O");
else
printf(" ");
if (k1 == 1 )
printf("O");
else
printf(" ");
if (l1 == 1 )
printf("O\n");
else
printf(" \n");
if (a2 == 1 )
printf("O");
else
printf(" ");
if (b2 == 1 )
printf("O");
else
printf(" ");
if (c2 == 1 )
printf("O");
else
printf(" ");
if (d2 == 1 )
printf("O");
else
printf(" ");
if (e2 == 1 )
printf("O");
else
printf(" ");
if (f2 == 1 )
printf("O");
else
printf(" ");
if (g2 == 1 )
printf("O");
else
printf(" ");
if (h2 == 1 )
printf("O");
else
printf(" ");
if (i2 == 1 )
printf("O");
else
printf(" ");
if (j2 == 1 )
printf("O");
else
printf(" ");
if (k2 == 1 )
printf("O");
else
printf(" ");
if (l2 == 1 )
printf("O\n");
else
printf(" \n");
if (a3 == 1 )
printf("O");
else
printf(" ");
if (b3 == 1 )
printf("O");
else
printf(" ");
if (c3 == 1 )
printf("O");
else
printf(" ");
if (d3 == 1 )
printf("O");
else
printf(" ");
if (e3 == 1 )
printf("O");
else
printf(" ");
if (f3 == 1 )
printf("O");
else
printf(" ");
if (g3 == 1 )
printf("O");
else
printf(" ");
if (h3 == 1 )
printf("O");
else
printf(" ");
if (i3 == 1 )
printf("O");
else
printf(" ");
if (j3 == 1 )
printf("O");
else
printf(" ");
if (k3 == 1 )
printf("O");
else
printf(" ");
if (l3 == 1 )
printf("O\n");
else
printf(" \n");
if (a4 == 1 )
printf("O");
else
printf(" ");
if (b4 == 1 )
printf("O");
else
printf(" ");
if (c4 == 1 )
printf("O");
else
printf(" ");
if (d4 == 1 )
printf("O");
else
printf(" ");
if (e4 == 1 )
printf("O");
else
printf(" ");
if (f4 == 1 )
printf("O");
else
printf(" ");
if (g4 == 1 )
printf("O");
else
printf(" ");
if (h4 == 1 )
printf("O");
else
printf(" ");
if (i4 == 1 )
printf("O");
else
printf(" ");
if (j4 == 1 )
printf("O");
else
printf(" ");
if (k4 == 1 )
printf("O");
else
printf(" ");
if (l4 == 1 )
printf("O\n");
else
printf(" \n");
if (a5 == 1 )
printf("O");
else
printf(" ");
if (b5 == 1 )
printf("O");
else
printf(" ");
if (c5 == 1 )
printf("O");
else
printf(" ");
if (d5 == 1 )
printf("O");
else
printf(" ");
if (e5 == 1 )
printf("O");
else
printf(" ");
if (f5 == 1 )
printf("O");
else
printf(" ");
if (g5 == 1 )
printf("O");
else
printf(" ");
if (h5 == 1 )
printf("O");
else
printf(" ");
if (i5 == 1 )
printf("O");
else
printf(" ");
if (j5 == 1 )
printf("O");
else
printf(" ");
if (k5 == 1 )
printf("O");
else
printf(" ");
if (l5 == 1 )
printf("O");
else
printf(" ");
}