tp5.c 2.17 KB
#include <stdio.h>
#include <string.h>

#define N 50


void setChaine (char *vect){
        scanf("%s", vect);
}

void afficheCar (char car, char nb){
    
    int nba;
    nba = nb - '0';
    int i ;
    for(i=1; i <= nba; i++){
        printf("%c", car);
    }
}

void insererCar (char * ch, char car, int* ind, char nb){
    int i ;
    int nba;
    nba = nb - '0';
     for(i=(*ind); i < (*ind)+nba; i++){
        ch[i] = car;
    }
    *ind = *ind + nba;
}



int chiffre(char ch){
    if ((ch >= '0') && (ch <= '9')){
        return 1;
    }else{
        return 0;
    }
}

int minuscule(char ch){
    if ((ch >= 'a') && (ch <= 'z')){
        return 1;
    }else{
        return 0;
    }
}


int majuscule(char ch){
    if ((ch >= 'A') && (ch <= 'Z')){
        return 1;
    }else{
        return 0;
    }
}

void traiterChain ( char v[], char res[]){
    int i;
  
    i = 0;
    int ind = 0;
    while(v[i] != '\0'){
        if(v[i+1]=='\0'){
              afficheCar(v[i],'1');
              insererCar(res,v[i],&ind,'1');
              i +=1;
        }else if(chiffre(v[i])){
            afficheCar(v[i+1],((v[i])+1));
            insererCar(res,v[i+1],&ind,((v[i])+1));
            i += 2;
        } else if(minuscule(v[i]) || majuscule(v[i])){
          
            afficheCar(v[i],'1');
            insererCar(res,v[i],&ind,'1');
            i += 1;
        } 
        
    }
    res[ind] = '\0';
    printf("---->%s",res);
}

/*void traiterChaine ( char v[]){
    int i;
  
    i = 0;
    while(v[i] != '\0'){
        if(v[i+1]=='\0'){
              afficheCar(v[i],'1');
              i +=1;
        }else if(chiffre(v[i])){
            afficheCar(v[i+1],((v[i])+1));
            i += 2;
        } else if(minuscule(v[i]) || majuscule(v[i])){
          
            afficheCar(v[i],'1');
            i += 1;
        } 
    }
}*/


void EncodChain ( char v[], char encode[]){
    int i;
    i = 0;
    char cCourant;
    
    while(v[i] != '\0'){
        if(v[i+1]=='\0'){
              insererCar(encode,v[i+1],&i,1);
              i +=1;
        
        
        }
    }
}



int main (){
    char vect[N];
    char decode[N];
    setChaine(vect);
    traiterChain(vect,decode);
    
    return 1;
}