Skip to content

Instantly share code, notes, and snippets.

@Sanix-Darker
Created April 8, 2023 10:05
Show Gist options
  • Save Sanix-Darker/7a264d91a9d0dfc53286693e2c3fd2ad to your computer and use it in GitHub Desktop.
Save Sanix-Darker/7a264d91a9d0dfc53286693e2c3fd2ad to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
const char *MORSE_TABLE[] = {
".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..",
".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.",
"...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
int main() {
char word[100];
int i, j, len;
printf("Enter a word: ");
scanf("%s", word);
len = strlen(word);
for (i = 0; i < len; i++) {
if (word[i] >= 'a' && word[i] <= 'z') {
j = word[i] - 'a'; // map a-z to 0-25
printf("%s ", MORSE_TABLE[j]);
} else if (word[i] >= 'A' && word[i] <= 'Z') {
j = word[i] - 'A'; // map A-Z to 0-25
printf("%s ", MORSE_TABLE[j]);
} else {
printf(" ");
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment