begin process at 2012 05 27 18:46:54
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Astuces

 > MORSE

MORSE


 Information sur la source

Note :
7 / 10 - par 1 personne
7,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Astuces Niveau :Débutant Date de création :09/07/2003 Date de mise à jour :09/07/2003 03:12:59 Vu :3 970

Auteur : jsk2004

Ecrire un message privé
Commentaire sur cette source (4)
Ajouter un commentaire et/ou une note

 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

TOUR_HANOI

 Sources de la même categorie

Source avec Zip Source avec une capture EVAL EXPRESSION COMPLEXE EN 15 LIGNES DE CODE par yann_lo_san
Source avec Zip SCHEDULER RR FIFO par yvesB87
Source avec Zip ALGORITHMES RÉCURSIFS VS ALGORITHMES ITÉRATIFS par yvesB87
Source avec Zip Source avec une capture C++ FORMAT D'IMAGE AVEC QT par pop70
Source avec une capture EXEMPLE DE POINTEURS DE FONCTION par pop70

Commentaires et avis

Commentaire de Kaid le 09/07/2003 11:55:43

une "sentence" ou une "séquence" ?

Commentaire de eRoZion le 09/07/2003 15:04:54

Une phrase, ca vient de la traduc.

Commentaire de Kirua le 10/07/2003 18:46:47

compile impec sous DevC++ (win32) enfin c normal en même temps puisque c le même compilo que sous linux ^^

Commentaire de eRoZion le 10/07/2003 19:04:17

Sous Borland C++ v4.x et v5.x ca passe sans problème non plus.

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,421 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales