//* struct used for lookup table - declaration and access *

#define __code // __code needed in embedded system, not in Visual Studio static __code const struct { const char letter; __code const char *morse; } cxTABLE[] = { { '0', "----- " }, //[0] { '1', ".---- " }, { '2', "..--- " }, { '3', "...-- " }, { '4', "....- " }, { '5', "..... " }, { '6', "-.... " }, { '7', "--... " }, { '8', "---.. " }, { '9', "----. " }, { 'A', ".- " }, //[10] { 'B', "-... " }, { 'C', "-.-. " }, { 'D', "-.. " }, { 'E', ". " }, { 'F', "..-. " }, { 'G', "--. " }, { 'H', ".... " }, { 'I', ".. " }, { 'J', ".--- " }, { 'K', ".-.- " }, //[20] { 'L', ".-.. " }, { 'M', "-- " }, { 'N', "-. " }, { 'O', "--- " }, { 'P', ".--. " }, { 'Q', "--.- " }, { 'R', ".-. " }, { 'S', "... " }, { 'T', "- " }, { 'U', "..- " }, //[30] { 'V', "...- " }, { 'W', ".-- " }, { 'X', "-..- " }, { 'Y', "-.-- " }, { 'Z', "--.. " }, { ' ', " " }, { '.', ".-.-.- " }, { ',', "--..-- " }, { '?', "..--.. " }, }; //[40] #include "stdio.h" void test1() { unsigned char c; while(1) { scanf("%c", &c); if (c>='A' && c<='Z') printf("%s\n", cxTABLE[ (c-'A'+10) ].morse); else if (c>='a' && c<='z') printf("%s\n", cxTABLE[ (c-'a'+10) ].morse); else if (c>='0' && c<='9') printf("%s\n", cxTABLE[ (c-'0') ].morse); else if (c==' ') printf("%s\n", cxTABLE[ 36 ].morse); else if (c=='.') printf("%s\n", cxTABLE[ 37 ].morse); else if (c==',') printf("%s\n", cxTABLE[ 38 ].morse); else if (c=='?') printf("%s\n", cxTABLE[ 39 ].morse); else if (c==1 /* ^A */) break; // graceful strategy for exiting this demo } } void test2() { unsigned char c; unsigned char i; while(1) { scanf("%c", &c); if (c>='a' && c<='z') c = c-'a'+'A'; else if (c==1 /* ^A */) break; // graceful strategy for exiting this demo for (i=0; i<40; i++) { if (cxTABLE[i].letter==c) break; } if (i<40) { printf("%s\n", cxTABLE[ i ].morse); } } } void main() { test1(); // test2(); }