#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
char str1[] = "Allez Alinghi!";
char *str2 = strdup(str1);
if (str2 == NULL)
{
printf("Erreur la duplication n'a pas foctionne correctemenent!!\n");
return (1);//ici pour quitter avec code de l erreur!
}
// afficher mes chaine
printf("str1 est %s\n", str1);
printf("str1 est devenu apres strdup %s\n", str2);
// Liberation de la memoire allouee par strdup
// remarque strdup cree un copie de str1, mais ne l ecrit pas 2x alors ok
free(str2);
return (0);
}
To embed this project on your website, copy the following code and paste it into your website's HTML: