Created
December 20, 2018 13:23
-
-
Save fabulousduck/d8ce224c17a088be51f2545a26fbb0df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <iostream> | |
#include <string> | |
std::string morseString; | |
void wait() { | |
printf("wait\n"); | |
} | |
void dash() { | |
printf("dash\n"); | |
} | |
void dot() { | |
printf("dot\n"); | |
} | |
void execMorse(int morseBuffer[]) { | |
for(int i = 0; i < 4; i++) { | |
switch(morseBuffer[i]) { | |
case 0: | |
wait(); | |
break; | |
case 1: | |
dot(); | |
break; | |
case 2: | |
dash(); | |
} | |
} | |
} | |
void execThing() { | |
int dict[26][4] = { | |
{1,2,0,0}, //a | |
{2,1,1,1}, //b | |
{2,1,2,1}, //c | |
{2,1,1,0}, //d | |
{1,0,0,0}, //e | |
{1,1,2,1}, //f | |
{2,2,1,0}, //g | |
{1,1,1,1}, //h | |
{1,1,0,0}, //i | |
{1,2,2,2}, //j | |
{2,1,2,0}, //k | |
{1,2,1,1}, //l | |
{2,2,0,0}, //m | |
{2,1,0,0}, //n | |
{2,2,2,0}, //o | |
{1,2,2,1}, //p | |
{2,2,1,2}, //q | |
{1,2,1,0}, //r | |
{1,1,1,0}, //s | |
{2,0,0,0}, //t | |
{1,1,2,0}, //u | |
{1,1,1,2}, //v | |
{2,1,1,2}, //x | |
{2,1,2,2}, //y | |
{2,2,1,1} //z | |
}; | |
const char *cstr = morseString.c_str(); | |
int i = 0; | |
while(cstr[i] != '\0') { | |
if(cstr == " ") { //160 is unicode space | |
i++; | |
continue; | |
} | |
execMorse(dict[cstr[i]-97]); | |
i++; | |
} | |
} | |
int main(int argc, char * argv[]) { | |
char tmp[101]; | |
if(argc > 1) { | |
morseString = argv[1]; | |
} else { | |
printf("enter some sentence>"); | |
scanf("%[^\n]", tmp); | |
morseString = tmp; | |
} | |
execThing(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment