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
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
char *creerLaChaine (char const *mot, int repetition)
{
char *retour = NULL;
if (mot != NULL && repetition > 0)
{
retour = malloc (strlen (mot) * repetition + 1);
if (retour != NULL)
{
*retour = 0;
int i = 0;
for (i = 0; i < repetition; i++)
{
strcat (retour, mot);
}
}
}
return retour;
}
int main (void)
{
char *s = creerLaChaine ("programmation", 6);
if (s != NULL)
{
printf ("chaine creee:'%s'\n", s);
free (s), s = NULL;
}
return 0;
} |
Partager