Created
April 8, 2023 10:05
-
-
Save Sanix-Darker/7a264d91a9d0dfc53286693e2c3fd2ad 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 <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