/*********************************************************** * This small program finds coincidences of letters in * * two given words of up to 26 letters. * * -------------------------------------------------------- * * SAMPLE RUN: * * * * Input first word : Bonjour * * Input second word: Monsieur * * * * The letter o is common to the two words. * * The letter n is common to the two words. * * The letter u is common to the two words. * * The letter r is common to the two words. * * * * -------------------------------------------------------- * * Reference: "Exercices en Turbo Pascal By Claude Delannoy * * Eyrolles, 1997". * * * * C++ Release By J-P Moreau, Paris. * * (www.jpmoreau.fr) * ***********************************************************/ #include #include #define Lmax 26 //max. length of a word #define FALSE 0 #define TRUE 1 char mot1[Lmax], //1st word mot2[Lmax]; //2nd word int found; //2 letters identical if TRUE int i,j; //loop counters int l1,l2; //length of mot1, mot2; void main() { // Read two words printf("\n Input first word : "); scanf("%s", mot1); printf(" Input second word: "); scanf("%s", mot2); printf("\n"); l1=strlen(mot1); l2=strlen(mot2); // Compare the two words for (i=0; i<=l1; i++) { found=FALSE; j=0; while (found==FALSE && j<=l2) { if (mot1[i]==mot2[j] && i!=l1 && j!=l2) { printf(" The letter %c is common to the two words.\n",mot1[i]); mot2[j]=' '; //to deactivate the found coincidence found=TRUE; } j++; } } printf("\n"); } // end of file comlet.cpp