I’m programming a microcontroller in C and as part of it want to display certain letters on a 7 segment display. Each letter has a corresponding number that makes the 7 segment display show the letter. There’s no real pattern to it cause the number is just made by adding up the bits on the 7 segment display that are needed to show the letter so it’d be really nice if I could create some sort of dictionary to do this.
If I was using C# or something I’d just make a dictionary and then add the letters as keys and the numbers as values but as far as I know I can’t do this in C. Is there another way to do it or do should I just write a function like int displayletter(char letter) that uses a bunch of if statements to return the right numbers?
You could create an array
and populate it with the values for each letter, however they’re calculated
Then create a function that takes a character and returns an int
This is simplistic, as it assumes you’ll only use upper case letters in an ASCII character set, but you should get the idea.