chaine.c 640 Bytes
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include "chaine.h"

void init_chaine(struct chaine* A){
    
    A->i=0;
    A->n=4;
    A->s=(char*)malloc(A->n*sizeof(char));

}

void ajout_chaine(struct chaine* A,char c){

    if(A->i==A->n){
        A->n=A->n+4;
        A->s=realloc(A->s,A->n*sizeof(char));
        A->s[A->i]=c;
        A->i=A->i+1;
        
    }else{
        A->s[A->i]=c;
        A->i=A->i+1;
    }
}


void imprime_chaine(struct chaine A){
    int j;
    
    for (j=0;j<=A.i;j++){
        printf("%c",A.s[j]);
    }
    printf("\n");
    
    
}

void clear_chaine(struct chaine* A){
    free(A->s);
}