#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char text[200];
int x, y;
char *characters[49] = { "------", ".----", "..---", "...--", "....-", ".....",
"-....", "--...", "---..", "----.", ".-", "-...",
"-.-.", "-..", ".", "..-", "--.", "....", "..",
".---", "-.-", ".-..", "--", "-.", "---", ".--.",
"--.-", ".-.", "...", "-", "..-", "...-", ".--",
"-..-", "-.--", "--..", "----", "--.--", ".-.-.-",
"---...", "--..--", "-.-.-.", ".----.", ".-..-.",
"..--..", "-.-.--", "-.--.", "-.--.-", " " };
char *ASCIItoMorse ( char *enty )
{
entry = text;
if ( entry[x] >= '0' && entry[x] <= '9' )
return characters[entry[x] - '0'];
else if ( enty[x] >= 'A' && entry[x] <= 'Z' )
return characters[entry[x] - 'A'];
else if ( entry[x] == 'ñ' )
return characters[38];
else if ( entry[x] >= 'a' && entry[x] <= 'z' )
return characters[entry[x] - 'a'];
else if ( entry[x] == '.' )
return characters[39];
else if ( entry[x] == ':' )
return characters[40];
else if ( entry[x] == ',' )
return characters[41];
else if ( entry[x] == ';' )
return characters[42];
else if ( entry[x] == '´' )
return characters[43];
else if ( entry[x] == '"' )
return characters[44];
else if ( entry[x] == '?' )
return characters[45];
else if ( entry[x] == '!' )
return characters[46];
else if ( entrada[x] == '(' )
return characters[47];
else if ( entry[x] == ')' )
return characters[48];
else if ( entry[x] == '' )
return characters[49];
}
int main ( void )
{
char *entry;
printf ( "Type your ASCII text:\n\n" );
entrada = gets ( text );
y = strlen ( text );
for ( x = 0; x <= y - 1; x++ )
printf ( "%s\n", ASCIItoMorse ( entrada[x] ) );
system ( "pause" );
}
>gets and "system pause"
These should be avoided, for starters... If you are unsure about input in c look here for ideas.