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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| # include <stdio.h>
# include <string.h>
# include <conio.h>
# define TAILLE 37
int main(){
struct code{
char lettre;
char *morse;
};
struct code table [TAILLE]={
{'A',".-"}, {'B',"-.."}, {'C',"-.-."},
{'D',"-.."}, {'E',"."}, {'F',"..-."},
{'G',"--."}, {'H',"...."}, {'I',".."},
{'J',".---"}, {'K',"-.-"}, {'L',".-.."},
{'M',"--"}, {'N',"-."}, {'O',"---"},
{'P',".--."}, {'Q',"--.-"}, {'R',".-."},
{'S',"..."}, {'T',"-"}, {'U',"..-"},
{'V',"...-"}, {'W',".--"}, {'X',"-..-"},
{'Y',"-.--"}, {'Z',"--.."}, {'.',".-.-.-"},
{'0',"-----"}, {'1',".----"}, {'2',"..---"},
{'3',"...--"}, {'4',"....-"}, {'5',"....."},
{'6',"-...."}, {'7',"--..."}, {'8',"---.."},
{'9',"----."}
};
char ligne[81], car[6], *d, *f, k=0;
int i, j, g=0, test=1, a, longligne;
printf("******************\n");
printf("*Traducteur Morse*\n");
printf("******************\n");
printf("\n1. Francais => Morse");
printf("\n2. Morse => Francais");
printf("\n0. Quitter");
printf("\n\n-> ");
do{
switch(getch()){
case '1':
printf("\n\n-> : ");
fgets(ligne, sizeof ligne, stdin);
fclean(ligne, stdin);
printf("\n=> : ");
strupr(ligne);
longligne=strlen(ligne);
for (i=0;i<longligne;i++){
j=0;
while (ligne[i]!=table[j].lettre && j++<TAILLE-1);
if (j<TAILLE) printf(" %s", table[j].morse);
else printf(" ??????");
if (!((i+1)%10)) printf("\n ");
}
break;
case '2':
printf("\n\n-> : ");
fgets(ligne, sizeof ligne, stdin);
fclean(ligne, stdin);
printf("\n=> : ");
d=ligne;
f=ligne;
while((*f!=' ') && (*f!=0)) f++;
for (i=0;ligne[i]!='\0';i++){
strncpy(car, d, (f-d));
do{
a=strcmp(car, table[g].morse);
g++;
}while(a==0);
if(a==1) printf("%c", table[g].lettre);
else printf(" ?????? ");
}
break;
case '0': test=0;
break;
default: printf("\n\nEntrez 1 ou 2");
break;
}
}while(test==1);
return 0;
} |
Partager