-
Notifications
You must be signed in to change notification settings - Fork 0
/
morse.c
39 lines (32 loc) · 1.08 KB
/
morse.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
const int BufferSize=256;
const char alphabet[26][6]=
{ ".-\0","-...\0","-.-.\0","-..\0",".\0","..-.\0","--.\0","....\0","..\0",".---\0","-.-\0",".-..\0","--\0","-.\0","---\0",".--.\0","--.-\0",".-.\0","...\0","-\0","..-\0","...-\0",".--\0","-..-\0","-.--\0","--..\0" };
void displayMorse(int i)
{
int l=0;
while( alphabet[i][l] != '\0' ) printf( "%c", alphabet[i][l++] );
}
int main(void)
{
char text[BufferSize];
int i=0;
/* initialize input buffer */
for( i=0;i<BufferSize;i++ ) text[i]='\0';
printf( "\n\n\n\n\n\n\n+=============================================================+\n|- t e x t 2 m o r s e b y : m r . p e l l e g r i n o -|\n+=============================================================+\n\nType letters to translate. Type * to quit.\n\n" );
while( text[0] != '*' )
{
int x;
scanf( "%s", &text );
unsigned long L = strlen( text );
for( i=0;i<(int)L;i++ )
{
x=text[i]-'a';
if( x<0 ) x=text[i]-'A';
displayMorse(x);
if( i < L-1 ) printf( "/" );
}
printf( "\n\n" );
}
return(0);
}