Skip to content

Instantly share code, notes, and snippets.

@yukixz
Created March 26, 2013 15:08
Show Gist options
  • Save yukixz/5246080 to your computer and use it in GitHub Desktop.
Save yukixz/5246080 to your computer and use it in GitHub Desktop.
/*
* @author: dazzyd
* @email: dazzyd2#gmail.com
* @license: BSD license
*/
#include <stdio.h>
#include <stdlib.h>
void printCode( char c )
{
switch(c) {
case 0: printf(".-"); break;
case 1: printf("-..."); break;
case 2: printf("-.-."); break;
case 3: printf("-.."); break;
case 4: printf("."); break;
case 5: printf("..-."); break;
case 6: printf("--."); break;
case 7: printf("...."); break;
case 8: printf(".."); break;
case 9: printf(".---"); break;
case 10: printf("-.-"); break;
case 11: printf(".-.."); break;
case 12: printf("--"); break;
case 13: printf("-."); break;
case 14: printf("---"); break;
case 15: printf(".--."); break;
case 16: printf("--.-"); break;
case 17: printf(".-."); break;
case 18: printf("..."); break;
case 19: printf("-"); break;
case 20: printf("..-"); break;
case 21: printf("...-"); break;
case 22: printf(".--"); break;
case 23: printf("-..-"); break;
case 24: printf("-.--"); break;
case 25: printf("--.."); break;
default: printf("ERROR: Char out of range!");
}
}
int main()
{
char ch;
srand( (int)time(0) ); // Set Random Seed
printf("Press 'ENTER' to generate a random Morse Code. 'q' to quit.\n");
while( ch=getchar() ) {
if (ch=='q') break;
if ( ch=='\n'||ch=='\r') printCode( rand()%26 );
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment