Accueil > > > MORSE
MORSE
Information sur la source
Description
PROGRAMME EXCUTEE SUR LINUX Red hat.
ce programme transforme une sentance au code morse.
le mots sont separees par des espace.
la deuxieme fonction de ce code et de transformer un code morse a une une sentence
les lettres sont separees par un espace et les mots en morse par trois espace.
et une astuce pour efacer l'ecran.
Source
- /* PROGRAMME ECECUTER SUR LINUX Red hat.
- Program Code morse
- ce programme transforme une sentance au code morse.
- le mots sont separees par des espace.
- la deuxieme fonction de ce code et de transformer un code morse a une une sentence
- les lettres sont separees par un espace et les mots en morse par trois espace.
-
- */
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #include<ctype.h>
- #define SIZE 100
- #define SIZE2 200
- void morse(char [],int );
- void morse_word(char []);
- void morse_sentence(char [],int);
- void help();
- char *saisie(char []);
- void clrscr();
- const char *lettres[37]={"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","1","2","3","4","5","6","7","8","9","0"};
- const char *code[37]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..",".----","..---","...--","....-",".....","-....","--...","---..","----.","-----"};
- char word[SIZE]={'\0'};
- int main()
- {
- char sentence[SIZE];
- //char *tokenptr;
- char con='c',c,choice;
- int i,j,k,stop=1,c1,cpt=0;
- do
- {
- i=0;
- clrscr();
- /* main menu for the program.
- select one option to enter in the program.*/
- printf("\t\t****************************************************\n");
- printf("\t\t* Code Morse *\n");
- printf("\t\t****************************************************\n");
- printf("\t\t* 1- Sentence to Morse *\n");
- printf("\t\t* 2- Morse to Sentence *\n");
- printf("\t\t* h- help Morse *\n");
- printf("\t\t* esc- exit *\n");
- printf("\t\t****************************************************\n\n");
- printf("\nEnter your choice please: \n");
- if (cpt==1)getchar();
- choice=getchar(); // select a choice.
- switch (choice)
- {
- case '1':// sentence to the morse. enter a sentence separte by espace.
- clrscr();
- cpt=1;
- printf("\t\t****************************************************\n");
- printf("\t\t* Code Morse *\n");
- printf("\t\t****************************************************\n");
- printf("\t\tSentence --------------> Morse\n");
- for (i=0;i<40;i++) // initialization for array word
- word[i]='\0';
- strcpy(sentence,saisie(sentence));
- morse(sentence,SIZE);// call morse function.
- break;
- case '2':// morse to a sentences, enter a morse code separete by espace for a lettres end tres space for word
- clrscr();
- cpt=1;
- printf("\t\t****************************************************\n");
- printf("\t\t* Code Morse *\n");
- printf("\t\t****************************************************\n");
- printf("\t\tMorse --------------> Sentence\n");
- for (i=0;i<40;i++) // intialiation de word
- word[i]='\0';
- strcpy(sentence,saisie(sentence));
-
- /*while(d=getchar()!='\n')
- sentence[j1++]=d;
- sentence[j1]='\0';*/
- morse_sentence(sentence,SIZE);// call morse sentence to detrminate word corepond for a morse code.
- break;
- case'h':
- cpt=1; // call function help to show table of morse and charactere
- help();
- break;
- case 27:// esc code ASCII 27=esc.
- cpt=1;
- stop=0;
- break;
- default :
- cpt=1;
- printf("Sorry !!!! Tray Again 'esc to end' please\n");
- break;
- }
- if (stop==1)
- {
- printf("Would you like to continue [c/n]");
- scanf("%s",&con);
- }
- }while ((con =='c')&&(stop==1));
- printf("\t\t*****************************************************\n");
- printf("\t\t\t End of the Program \n");
- printf("\t\t*****************************************************\n");
- return 0;
- }
- //****************************************************************************
- void morse(char sent[],int size)
- {
- char morse[SIZE2]={'\0'};
- char word1[SIZE];
- char *ptrtoken;
- int ln,i,stp=1,j=0,stop=1;
- ptrtoken=strtok(sent," "); // point in the first word
- while (ptrtoken !=NULL)
- {
- strcpy(word1,ptrtoken); // copy in word1 a content of the pointer
- ln=strlen(word1);
- for (i=0;i<ln;i++)
- word1[i]= toupper(word1[i]);// determinate for each lettre a code morse corespond
- for (i=0;i<ln;i++)
- {
- stp=1;
- j=0;
- while ((j<=36)&& ( stp==1))
- {
- if (word1[i]==*lettres[j])
- {
-
- strcat(morse,code[j]);
- strcat(morse," ");
- stp=0;
- }
- j++;
- if ((j==36)&& (stp==1)){ stop=0;break;}
- }
- }
- if (stop==0) {strcpy(morse,"no Morese*******");break;}
- strcat(morse," ");// separe a word
- ptrtoken=strtok(NULL," "); // next word until end
- }
- printf("Code Morse for the sentence is :\n %s \n",morse);// desplay a word.
- }
-
- //***********************
- void morse_sentence(char sent[],int size)
- {
- char mot[SIZE2]={'\0'};
- char sent_tmp[SIZE2]={'\0'};
- char word_tmp[40];
- char word_tmp1[40];
- char *ptrword,*ptrtok;
- int ln,i=0,j=0,stp=1,stop=0;
- strcpy(sent_tmp,sent);
- ln=strlen(sent);
-
- while (i<=ln)
- {
-
- if ((sent_tmp[i]==' ') && (sent_tmp[i+1] == ' '))
- {
- morse_word(mot); // call the morse function
- strcat(word," ");// separe a word
- i=i+2;
- j=0;
-
- }
- else
- {
- mot[j]=sent_tmp[i];
- j++;
- }
- i++;
- }
- morse_word(mot);
- ln=strlen(word);
- for (i=0;i<ln;i++) word[i]=tolower(word[i]);//desplay a word
- printf("\nthe Sentence for the Morse is :\n %s\n\n",word);
-
- }
- //**************************************************
- void clrscr()
- { // seulement sur LINUX pour efacer l'ecran
- printf("\033[2J");
- printf("\033[0;0f");
-
- }
- //*************************************************
- void help()// desplay morse table
- {
- int i;
- printf("*****************************************************************\n");
- printf("\t\tCharater and Code Morse\n");
- printf("*****************************************************************\n");
- for (i=1;i<37;i++)
- {
- printf("%1s <=> %s\t",lettres[i-1],code[i-1]);
- if (i%4 ==0) printf("\n");
- }
- printf("*****************************************************************\n");
- }
- //**************************************************
- char *saisie(char sentence[])// enter a sentence to converte
- {
- char c1;
- printf("\nEnter your sentences please \n");
- c1=getchar();
- gets(sentence);
- return sentence;
- }
- //*********************************************************
- void morse_word(char mot [])
- {
- char word_tmp[SIZE]={'\0'};
- char *ptrtoken;
- int stp=1,j,stop=0;
- ptrtoken=strtok(mot," ");// point to a first lettre
- while (ptrtoken!=NULL)
- {
- stp=1;
- j=0;
- while ((j<=36)&&(stp==1))
- {
- if (strcmp(ptrtoken,code[j])==0) // search a lettres corespond to a code morse
- {
- strcat(word_tmp,lettres[j]);
- stp=0;
- }
- j++;
- if ((j>=36)&& (stp==1)){ stop=1;break;} // case a the code dont exist in morse table.
- }
- if (stop==1) break;
- ptrtoken=strtok(NULL," ");
- }
- if (stop==1)
- {
- strcpy(word," No word* *************** ");
- }
- else
- strcat(word,word_tmp);
- }
- //*************************************************************
/* PROGRAMME ECECUTER SUR LINUX Red hat.
Program Code morse
ce programme transforme une sentance au code morse.
le mots sont separees par des espace.
la deuxieme fonction de ce code et de transformer un code morse a une une sentence
les lettres sont separees par un espace et les mots en morse par trois espace.
*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#define SIZE 100
#define SIZE2 200
void morse(char [],int );
void morse_word(char []);
void morse_sentence(char [],int);
void help();
char *saisie(char []);
void clrscr();
const char *lettres[37]={"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","1","2","3","4","5","6","7","8","9","0"};
const char *code[37]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..",".----","..---","...--","....-",".....","-....","--...","---..","----.","-----"};
char word[SIZE]={'\0'};
int main()
{
char sentence[SIZE];
//char *tokenptr;
char con='c',c,choice;
int i,j,k,stop=1,c1,cpt=0;
do
{
i=0;
clrscr();
/* main menu for the program.
select one option to enter in the program.*/
printf("\t\t****************************************************\n");
printf("\t\t* Code Morse *\n");
printf("\t\t****************************************************\n");
printf("\t\t* 1- Sentence to Morse *\n");
printf("\t\t* 2- Morse to Sentence *\n");
printf("\t\t* h- help Morse *\n");
printf("\t\t* esc- exit *\n");
printf("\t\t****************************************************\n\n");
printf("\nEnter your choice please: \n");
if (cpt==1)getchar();
choice=getchar(); // select a choice.
switch (choice)
{
case '1':// sentence to the morse. enter a sentence separte by espace.
clrscr();
cpt=1;
printf("\t\t****************************************************\n");
printf("\t\t* Code Morse *\n");
printf("\t\t****************************************************\n");
printf("\t\tSentence --------------> Morse\n");
for (i=0;i<40;i++) // initialization for array word
word[i]='\0';
strcpy(sentence,saisie(sentence));
morse(sentence,SIZE);// call morse function.
break;
case '2':// morse to a sentences, enter a morse code separete by espace for a lettres end tres space for word
clrscr();
cpt=1;
printf("\t\t****************************************************\n");
printf("\t\t* Code Morse *\n");
printf("\t\t****************************************************\n");
printf("\t\tMorse --------------> Sentence\n");
for (i=0;i<40;i++) // intialiation de word
word[i]='\0';
strcpy(sentence,saisie(sentence));
/*while(d=getchar()!='\n')
sentence[j1++]=d;
sentence[j1]='\0';*/
morse_sentence(sentence,SIZE);// call morse sentence to detrminate word corepond for a morse code.
break;
case'h':
cpt=1; // call function help to show table of morse and charactere
help();
break;
case 27:// esc code ASCII 27=esc.
cpt=1;
stop=0;
break;
default :
cpt=1;
printf("Sorry !!!! Tray Again 'esc to end' please\n");
break;
}
if (stop==1)
{
printf("Would you like to continue [c/n]");
scanf("%s",&con);
}
}while ((con =='c')&&(stop==1));
printf("\t\t*****************************************************\n");
printf("\t\t\t End of the Program \n");
printf("\t\t*****************************************************\n");
return 0;
}
//****************************************************************************
void morse(char sent[],int size)
{
char morse[SIZE2]={'\0'};
char word1[SIZE];
char *ptrtoken;
int ln,i,stp=1,j=0,stop=1;
ptrtoken=strtok(sent," "); // point in the first word
while (ptrtoken !=NULL)
{
strcpy(word1,ptrtoken); // copy in word1 a content of the pointer
ln=strlen(word1);
for (i=0;i<ln;i++)
word1[i]= toupper(word1[i]);// determinate for each lettre a code morse corespond
for (i=0;i<ln;i++)
{
stp=1;
j=0;
while ((j<=36)&& ( stp==1))
{
if (word1[i]==*lettres[j])
{
strcat(morse,code[j]);
strcat(morse," ");
stp=0;
}
j++;
if ((j==36)&& (stp==1)){ stop=0;break;}
}
}
if (stop==0) {strcpy(morse,"no Morese*******");break;}
strcat(morse," ");// separe a word
ptrtoken=strtok(NULL," "); // next word until end
}
printf("Code Morse for the sentence is :\n %s \n",morse);// desplay a word.
}
//***********************
void morse_sentence(char sent[],int size)
{
char mot[SIZE2]={'\0'};
char sent_tmp[SIZE2]={'\0'};
char word_tmp[40];
char word_tmp1[40];
char *ptrword,*ptrtok;
int ln,i=0,j=0,stp=1,stop=0;
strcpy(sent_tmp,sent);
ln=strlen(sent);
while (i<=ln)
{
if ((sent_tmp[i]==' ') && (sent_tmp[i+1] == ' '))
{
morse_word(mot); // call the morse function
strcat(word," ");// separe a word
i=i+2;
j=0;
}
else
{
mot[j]=sent_tmp[i];
j++;
}
i++;
}
morse_word(mot);
ln=strlen(word);
for (i=0;i<ln;i++) word[i]=tolower(word[i]);//desplay a word
printf("\nthe Sentence for the Morse is :\n %s\n\n",word);
}
//**************************************************
void clrscr()
{ // seulement sur LINUX pour efacer l'ecran
printf("\033[2J");
printf("\033[0;0f");
}
//*************************************************
void help()// desplay morse table
{
int i;
printf("*****************************************************************\n");
printf("\t\tCharater and Code Morse\n");
printf("*****************************************************************\n");
for (i=1;i<37;i++)
{
printf("%1s <=> %s\t",lettres[i-1],code[i-1]);
if (i%4 ==0) printf("\n");
}
printf("*****************************************************************\n");
}
//**************************************************
char *saisie(char sentence[])// enter a sentence to converte
{
char c1;
printf("\nEnter your sentences please \n");
c1=getchar();
gets(sentence);
return sentence;
}
//*********************************************************
void morse_word(char mot [])
{
char word_tmp[SIZE]={'\0'};
char *ptrtoken;
int stp=1,j,stop=0;
ptrtoken=strtok(mot," ");// point to a first lettre
while (ptrtoken!=NULL)
{
stp=1;
j=0;
while ((j<=36)&&(stp==1))
{
if (strcmp(ptrtoken,code[j])==0) // search a lettres corespond to a code morse
{
strcat(word_tmp,lettres[j]);
stp=0;
}
j++;
if ((j>=36)&& (stp==1)){ stop=1;break;} // case a the code dont exist in morse table.
}
if (stop==1) break;
ptrtoken=strtok(NULL," ");
}
if (stop==1)
{
strcpy(word," No word* *************** ");
}
else
strcat(word,word_tmp);
}
//*************************************************************
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
MATRICE TEMPLATEMATRICE TEMPLATE par hjr2610
Cliquez pour lire la suite par hjr2610 RE : SAC A DOS RE : SAC A DOS par hadjkaddour
Cliquez pour lire la suite par hadjkaddour
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|