Question: Can you please fehlp ix the errors in the code or tell me why it doesn't work? Also, I use visual studio 2022 for this.
Can you please fehlp ix the errors in the code or tell me why it doesn't work?
Also, I use visual studio 2022 for this.
#include
#include
#include
#include
#include
int main()
{
int sel;
char word[1024];
unsigned char reg = 0;
while (1)
{
printf("1) Author info 2) check status 3) clear status 4) save status 5) load status 6) set LED color 7) Set user value 8) toggle reset 9) turn on 10) turn off 11) Shift 12) Set value 0) Exit ");
printf("Enter your choice: ");
scanf("%d", &sel);
switch (sel)
{
case 1:
printf("Author: Angelo Figueroa Student ID: 2788887 ");
break;
case 2:
printf("Value of stored value: %d ", reg);
printf("Power: ");
if ((reg & 0x01) == 0) printf("OFF ");
else
{
printf("ON ");
printf("Color: ");
if ((reg & 0x60) == 0x00) printf("OFF ");
else if ((reg & 0x60) == 0x20) printf("Red ");
else if ((reg & 0x60) == 0x40) printf("Green ");
else if ((reg & 0x60) == 0x60) printf("Blue ");
printf("Reset: ");
if ((reg & 0x80) == 0x00) printf("Low ");
else printf("High ");
printf("User value: %d ", (reg & 0x18) >> 3);
}
break;
case 3:
reg = 0;
break;
case 4:
printf("Enter file name: ");
scanf("%s", word);
int fd = open(word, O_RDWR | O_CREAT, 0666); //error 2
write(fd, , sizeof(reg)); //error 3&4
close(fd); //error 5
break;
case 5:
printf("Enter file name: ");
scanf("%s", word);
int fd = open(word, O_RDONLY);
read(fd, , sizeof(reg));
close(fd);
break;
case 6:
printf("Enter LED color (0-OFF, 1-Red, 2-Green, 3-Blue): ");
int color;
scanf("%d", &color);
reg &= ~0x60;
switch (color)
{
case 1:
reg |= 0x20;
break;
case 2:
reg |= 0x40;
break;
case 3:
reg |= 0x60;
break;
}
break;
case 7:
printf("Enter two binary bits (in decimal form): ");
int bit1, bit2;
scanf("%d%d", &bit1, &bit2); reg &= ~0x18;
reg |= (bit1
break;
case 8: reg ^= 0x80;
break;
case 9: reg |= 0x01;
break;
case 10: reg &= ~0x01;
break;
case 11: printf("Enter shift value (1-left, 2-right): "); int shift; scanf("%d", &shift); if (shift == 1) { int temp = (reg & 0x01) >= 1; reg |= temp; }
else if (shift == 2) {
int temp = (reg & 0x80) >> 7;
reg
} break;
case 12: printf("Enter 8-bit value: ");
int value; scanf("%d", &value);
reg = value;
break;
case 0:
return 0;
break;
default: printf("Invalid choice ");
break;
}
}
return 0;
}

Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
