I am trying to concatenate strings with numeric (double) values and texts.
My current code:
char nameLed[256]; //Nom de la led
char colorLed[256]; //La couleur de la led
char I_directLed[100]; //L'intensité direct que peut supporter la led
double U_directLed; //La tension direct que peut supporter la led
char commentLed[256]; //Le commentaire sur la led
char chaineSaveLed[1000];//Chaine concaténé
GetCtrlVal(panel, TABPANEL_1_ST_Name, nameLed); //Panel > Tab Champ
GetCtrlVal(panel, TABPANEL_1_ST_Color, colorLed); //Panel > Tab Champ
GetCtrlVal(panel, TABPANEL_1_I_Direct_Led, &I_directLed); //Panel > Tab Champ
GetCtrlVal(panel, TABPANEL_1_U_Led_Direct, &U_directLed); //Panel > Tab Champ
GetCtrlVal(panel, TABPANEL_1_TXT_Comment, commentLed); //Panel > Tab Champ
//Créer la chaine à enregistrer au format CSV
//Concaténation de chaine
strcat (chaineSaveLed, nameLed);
strcat (chaineSaveLed, ",");
strcat (chaineSaveLed, colorLed);
strcat (chaineSaveLed, ",");
strcat (chaineSaveLed, I_directLed);
strcat (chaineSaveLed, ",");
strcat (chaineSaveLed, U_directLed);
strcat (chaineSaveLed, ",");
strcat (chaineSaveLed, commentLed);
strcat (chaineSaveLed, "/n");
printf ("%s\n", chaineSaveLed);
My problem is on "I_directLed" and "U_directLed".
I have to convert the double to char.
Thanks for your help.
If I understand what you mean correctly, the best way to do this is using sprintf(). It allows you to write to a string and format it, similar to how printf() works. So for example, you could replace your code with: