• [^] # Re: C

    Posté par . En réponse au message Caractère de padding. Évalué à 1.

    Merci pour cette méthode. Débutant en C et autodidacte, je ne connaissais pas l'utilisation de l'étoile pour passer un paramètre dans le format de printf.

    Personnellement, j'écrirais :

    #define NB_CHAR 15
    #define ALIGNER_AVEC_PADDING(str) NB_CHAR - (int)strlen(str), padding, str
    char padding[255] = { [0 ... 253] = '.', [254] = 0 }; /* ATTENTION gcc uniquement */
    char *str = "hello";
    printf("%.*s%s\n",ALIGNER_AVEC_PADDING(str) );

    Qu'en pensez-vous ?