I need to make a simple translator. For example:
- input: "foo" output: "bar"
- input: "the" output: "teh"
- input: "what" output: "wut"
I know I can write it like this:
if (!strcmp(input, "foo"))
puts("bar");
else if (!strcmp(input, "the"))
puts("teh");
else if (!strcmp(input, "what"))
puts("wut");
But that's big and messy. Is there a shortcut to do this? I know that in PHP (sorry for the inevitable syntax errors, I'm not proficient) there's something like this:
value = array(
"foo" => "bar",
"the" => "teh",
"what" => "wut"
);
How can I shorten the original code using something like a PHP array?