- char * AjusterTailleChaine(char * Chaine, long PositionAjustement, long NDeplacement)
- {
- if ((Chaine[0]=='\0')||(PositionAjustement<0))
- {
- return Chaine;
- }
-
- if (NDeplacement==0)
- {
- return Chaine;
- }
- long LongChaine=strlen(Chaine);
- long IndiceGauche;
- long IndiceDroit;
- char* chaineCopie;
-
- if (NDeplacement<0)
- {
- IndiceDroit = 0;
- IndiceGauche = 0 ;
- chaineCopie = (char*) malloc(((strlen(Chaine) + NDeplacement) * sizeof(char)));
-
- while(Chaine[IndiceDroit] != '\0')
- {
- if((IndiceDroit<PositionAjustement)||(IndiceDroit>=PositionAjustement-NDeplacement))
- {
- chaineCopie[IndiceGauche]= Chaine[IndiceDroit];
- IndiceGauche= IndiceGauche + 1;
- }
-
-
- IndiceDroit= IndiceDroit + 1;
- }
- chaineCopie[IndiceGauche]= '\0';//Chaine[IndiceDroit]; // Refermer la chaine par un EOS
- return chaineCopie ;
- }
-
- if (NDeplacement>0)
- {
- int Taille = strlen(Chaine)-1;
- chaineCopie = (char*) malloc((Taille + NDeplacement) * sizeof(char));
- int Indice= Taille;
- strcpy(chaineCopie, Chaine);
- chaineCopie[Indice + NDeplacement + 1] = 0;
- while(Indice >= PositionAjustement )
- {
- chaineCopie[Indice + NDeplacement] = Chaine[Indice];
- Indice--;
- }
- for(int i = 0; i < NDeplacement ; i++)
- {
- chaineCopie[PositionAjustement + i] = ' ';
- }
- return chaineCopie;
-
- }
- }
char * AjusterTailleChaine(char * Chaine, long PositionAjustement, long NDeplacement)
{
if ((Chaine[0]=='\0')||(PositionAjustement<0))
{
return Chaine;
}
if (NDeplacement==0)
{
return Chaine;
}
long LongChaine=strlen(Chaine);
long IndiceGauche;
long IndiceDroit;
char* chaineCopie;
if (NDeplacement<0)
{
IndiceDroit = 0;
IndiceGauche = 0 ;
chaineCopie = (char*) malloc(((strlen(Chaine) + NDeplacement) * sizeof(char)));
while(Chaine[IndiceDroit] != '\0')
{
if((IndiceDroit<PositionAjustement)||(IndiceDroit>=PositionAjustement-NDeplacement))
{
chaineCopie[IndiceGauche]= Chaine[IndiceDroit];
IndiceGauche= IndiceGauche + 1;
}
IndiceDroit= IndiceDroit + 1;
}
chaineCopie[IndiceGauche]= '\0';//Chaine[IndiceDroit]; // Refermer la chaine par un EOS
return chaineCopie ;
}
if (NDeplacement>0)
{
int Taille = strlen(Chaine)-1;
chaineCopie = (char*) malloc((Taille + NDeplacement) * sizeof(char));
int Indice= Taille;
strcpy(chaineCopie, Chaine);
chaineCopie[Indice + NDeplacement + 1] = 0;
while(Indice >= PositionAjustement )
{
chaineCopie[Indice + NDeplacement] = Chaine[Indice];
Indice--;
}
for(int i = 0; i < NDeplacement ; i++)
{
chaineCopie[PositionAjustement + i] = ' ';
}
return chaineCopie;
}
}