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
| #include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include "Mot.h"
MOT_Mot MOT_creationMot(char* chaine){
assert( strlen(chaine)>0 );
MOT_Mot unMot;
unsigned int i;
unMot.mot=NULL;
strcpy(unMot.mot,chaine);
unMot.longueur=strlen(unMot.mot);
for (i=0; i<unMot.longueur; i++) {
unMot.mot[i]=toupper(unMot.mot[i]);
}
return unMot;
}
unsigned int MOT_longueur(MOT_Mot unMot){
return unMot.longueur;
}
char MOT_iEmeLettre(MOT_Mot unMot, unsigned int pos){
assert(pos<MOT_longueur(unMot));
return unMot.mot[pos];
}
void MOT_insererCaractere(MOT_Mot* unMot, char caractere, unsigned int pos){
assert(pos<MOT_longueur(*unMot));
unsigned int i;
for(i=unMot->longueur;i>=pos;i--){
unMot->mot[i+1]=unMot->mot[i];
}
unMot->mot[pos]=caractere;
unMot->longueur=unMot->longueur+1;
}
void MOT_supprimerCaractere(MOT_Mot* unMot, unsigned int pos){
assert(pos<MOT_longueur(*unMot) && MOT_longueur(*unMot)>1);
unsigned int i;
for(i=pos;i<=strlen(unMot->mot);i++){
unMot->mot[i]=unMot->mot[i+1];
}
unMot->longueur=unMot->longueur-1;
}
void permuter_ch(char * a, char * b)
{
char k;
k=*a;
*a=*b;
*b=k;
}
void MOT_echangerCaractere(MOT_Mot* unMot, unsigned int pos1, unsigned int pos2){
assert(pos1<MOT_longueur(*unMot) && pos2<MOT_longueur(*unMot) && MOT_longueur(*unMot)>1);
permuter_ch(&unMot->mot[pos1],&unMot->mot[pos2]);
}
int MOT_estIdentique(MOT_Mot premierMot,MOT_Mot deuxiemeMot){
unsigned int n;
if (MOT_longueur(premierMot)!=MOT_longueur(deuxiemeMot))
return 0;
else { n=strlen(premierMot.mot);
if ( premierMot.mot[n]!= deuxiemeMot.mot[n]){
return 0;}
else {
if (n>1){
MOT_supprimerCaractere(&premierMot,n);
MOT_supprimerCaractere(&deuxiemeMot,n);
return MOT_estIdentique(premierMot,deuxiemeMot);
}
else
return 1;
}
}
}
char* MOT_motEnChaine(MOT_Mot unMot){
unsigned int i;
char* chaine=(char*)malloc(sizeof(unMot.longueur));
chaine="";
for(i=1;i<=unMot.longueur;i++){
chaine[i]=unMot.mot[i];
}
return chaine;
} |
Partager