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
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
char * enc_quotedP(char const * string) {
char * textqp = NULL;
if (string) {
fprintf(stdout,"Taille de string : %lu\n",(unsigned long)strlen(string));
textqp = malloc(3*strlen(string)+1);
if (textqp) {
int i=0, j=0;
unsigned char c = 0u;
char qp_char[3+1] = { '\0' };
while(*(string + i) !='\0') {
if (*(string + i) >= 0 && *(string + i) < SCHAR_MAX) {
*(textqp + j) = *(string + i);
++j;
}
else {
c = *(string + i);
sprintf(qp_char, "=%02X", c);
strcat(textqp, qp_char);
j+=3;
}
++i;
}
}
else {
fprintf(stderr,"Erreur de Malloc\n");
}
}
return textqp;
}
int main(void) {
char * texteQP = NULL;
char const * texte;
texte = "Les accents : à é è ç";
texteQP = enc_quotedP(texte);
if (texteQP) {
fprintf(stdout,"Texte : %s\nTexte quoted-printable : %s\n",texte, texteQP);
}
else {
fprintf(stderr,"Conversion texte -> texteQP a echoue\n");
}
return 0;
} |
Partager