Im making a program called Bulbs for the cs50x course. The program is supposed to output an inputted string into binary, using either yellow or black color for on and off in the terminal. I've tried with a few numbers as inputs, like 1 and 4, and it displays it correctly besides the third and fourth bulb that are ALWAYS on, no matter the input. Can you see why? Thanks in advance!
EDIT: I tried inputs "1" and "4", the terminal output are the yellow and black colors respective to digits 1 and 2. So for example if I inputted "1" id get: black, black, yellow, yellow, black, black, black, yellow (00110001) instead of (00000001).
EDIT 2: Everything works well now. It seems I just didnt uderstand ASCII. Thank you very much!! I almost cried when I saw every condition for sumbitting the code in green. Have a great day
#include <cs50.h>
#include <stdio.h>
#include <string.h>
const int BITS_IN_BYTE = 8;
void print_bulb(int bit);
int main(void) {
string text = get_string("Text to encrypt!: ");
int bit;
int n = strlen(text);
int array[BITS_IN_BYTE] = {0, 0, 0, 0, 0, 0, 0, 0};
int count = 0;
for ( int i = 0; i < n ; i++) {
for (int j = 0, x = 7; j < 8 && x >= 0; j++, x--) {
if (text[i] == 0) {
array[x] = 0;
}
else if (text[i] == 1) {
array[x] = 1;
text[i] = 0;
}
else if (text[i] != 1 && text[i] != 0) {
array[x] = text[i] % 2;
text[i] = text[i]/2; //jak dojdzie do 1 to?
}
}
for (int y = 0; y <= 7; y++) {
print_bulb(array[y]);
}
printf("\n");
}
}
void print_bulb(int bit) {
if (bit == 0) {
// Dark emoji
printf("\U000026AB");
}
else if (bit == 1) {
// Light emoji
printf("\U0001F7E1");
}
}