- #include <stdio.h>
- #include <conio.h>
- #include <stdarg.h>
- #include <string.h>
- // ---------------------------------------------------------
- // Fais des 'strcat' a la suite sur la chaine 'pOut'
- // Les chaines ajoutees sont passees en argument
- // La derniere chaine doit etre '""' (vide)
- // Retourne le nombre de chaine ajoutees
- int myStrcat(char *pOut,...)
- {
- va_list listStringToAdd;
- int nbStringAdded;
- // initialisation
- va_start(listStringToAdd,pOut);
- nbStringAdded = 0;
- // on commence a balayer toutes les chaines jusqu'a ""
- do
- {
- char *stringToAdd;
- // on obtient la chaine a ajouter
- stringToAdd = va_arg(listStringToAdd,char *);
- // si l'on doit arreter
- if(*stringToAdd == '\0')
- {
- break;
- }
- // on l'ajoute
- strcat(pOut,stringToAdd);
- nbStringAdded ++;
- }while(1);
- // on referme gentillement
- va_end(listStringToAdd);
- return nbStringAdded;
- }
- // ---------------------------------------------------------
- int main(int argc,char **argv)
- {
- char buf[256] = "Coucou ici la premiere chaine\n";
- int i;
-
- i = myStrcat(buf,
- "--- AJOUTS ---\n",
- "hello world\n",
- "vive la programmation en C/C++ !\n",
- "www.cppfrance.com\n",
- "--- FIN ---\n",
- ""
- );
- printf("\n%d chaine(s) ajoutee(s)\n\n%s\n",i,buf);
-
- getch();
- return 0;
- }
#include <stdio.h>
#include <conio.h>
#include <stdarg.h>
#include <string.h>
// ---------------------------------------------------------
// Fais des 'strcat' a la suite sur la chaine 'pOut'
// Les chaines ajoutees sont passees en argument
// La derniere chaine doit etre '""' (vide)
// Retourne le nombre de chaine ajoutees
int myStrcat(char *pOut,...)
{
va_list listStringToAdd;
int nbStringAdded;
// initialisation
va_start(listStringToAdd,pOut);
nbStringAdded = 0;
// on commence a balayer toutes les chaines jusqu'a ""
do
{
char *stringToAdd;
// on obtient la chaine a ajouter
stringToAdd = va_arg(listStringToAdd,char *);
// si l'on doit arreter
if(*stringToAdd == '\0')
{
break;
}
// on l'ajoute
strcat(pOut,stringToAdd);
nbStringAdded ++;
}while(1);
// on referme gentillement
va_end(listStringToAdd);
return nbStringAdded;
}
// ---------------------------------------------------------
int main(int argc,char **argv)
{
char buf[256] = "Coucou ici la premiere chaine\n";
int i;
i = myStrcat(buf,
"--- AJOUTS ---\n",
"hello world\n",
"vive la programmation en C/C++ !\n",
"www.cppfrance.com\n",
"--- FIN ---\n",
""
);
printf("\n%d chaine(s) ajoutee(s)\n\n%s\n",i,buf);
getch();
return 0;
}