Skip to content

Commit

Permalink
Morse decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Martinsson committed Oct 23, 2014
1 parent 2069631 commit b563449
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions morse-decode.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

const char *alphabet[] = {
".-", "A",
"-...", "B",
"-.-.", "C",
"-..", "D",
".", "E",
"..-.", "F",
"--.", "G",
"....", "H",
"..", "I",
".---", "J",
"-.-", "K",
".-..", "L",
"--", "M",
"-.", "N",
"---", "O",
".--.", "P",
"--.-", "Q",
".-.", "R",
"...", "S",
"-", "T",
"..-", "U",
"...-", "V",
".--", "W",
"-..-", "X",
"-.--", "Y",
"--..", "Z",
"-----", "0",
".----", "1",
"..---", "2",
"...--", "3",
"....-", "4",
".....", "5",
"-....", "6",
"--...", "7",
"---..", "8",
"----.", "9",
".-.-.-", ".",
"--..-- ", ",",
"/", " ",
};

int main(int argc, char **argv) {
for (int i = 0; i < argc; i++) {
for (int c = 0; c < sizeof(alphabet)/sizeof(char*); c+=2) {
if (strcmp(alphabet[c], argv[i]) == 0) {
printf("%s", alphabet[c+1]);
break;
}
}
}
printf("\n");
}

0 comments on commit b563449

Please sign in to comment.