Bonjour,
Voici un petit essai :
#include <stdio.h>
void Convertir
(
const char* pszEntree // E:chaîne à convertir
,char* pszSortie // S:chaîne résultat
)
{
const char* pcEntree = pszEntree;
char* pcSortie = pszSortie;
*pcSortie = 0; // terminateur par défaut
// --- Pointer derrière le ':'
while (*pcEntree && *pcEntree != ':') ++pcEntree;
if (*pcEntree != ':') return; // chaîne incorrecte
++pcEntree; // saute ':'
// --- Remplir la chaîne résultat
while(*pcEntree)
{
*pcSortie++ = '\\';
*pcSortie++ = 'x';
*pcSortie++ = *pcEntree++;
*pcSortie++ = *pcEntree++;
if (*pcEntree == ',') ++pcEntree; // saute ','
}
*pcSortie = 0; // terminateur
}
int main(void)
{
const char* szChaine = "hex:4e,5b,00,3c";
char szResultat[32];
Convertir(szChaine,szResultat);
printf("Entree = %s\n",szChaine);
printf("Sortie = %s\n",szResultat);
return 0;
}
Ce qui donne :
Entree = hex:4e,5b,00,3c
Sortie = \x4e\x5b\x00\x3c
Jean-François