61 lines
1.2 KiB
C
61 lines
1.2 KiB
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
char *strdup(const char *s);
|
|
|
|
|
|
void my_strapp(char *src, char **dest){
|
|
|
|
if (src == NULL || dest == NULL) return;
|
|
|
|
//taille src
|
|
int index = 0;
|
|
while (*(src + index)) index ++;
|
|
|
|
//taille desti
|
|
int index_dest = 0;
|
|
while (*(*dest + index_dest)) index_dest ++;
|
|
|
|
//realloc des dest avec la taille de src
|
|
*dest = realloc(*dest, index + index_dest + 1);
|
|
//int *dest = realloc(*dest, index);
|
|
|
|
if (dest == NULL) return;
|
|
|
|
index = 0;
|
|
/*while(*(new + index_dest)){
|
|
|
|
printf("%c", *(new + index_dest));
|
|
|
|
index_dest ++;
|
|
}
|
|
printf("\n");
|
|
//index_dest --;
|
|
while(*(src + index)){
|
|
|
|
*(new + (index_dest+ index)) = *(src + index);
|
|
index ++;
|
|
}*/
|
|
|
|
while(*(src + index)){
|
|
*(*dest + index_dest + index) = *(src + index);
|
|
index ++;
|
|
}
|
|
|
|
*(dest + index_dest + index + 1) = '\0';
|
|
|
|
|
|
}
|
|
/*
|
|
int main(){
|
|
|
|
char *src = strdup("World!");
|
|
char *dest = strdup("Hello, ");
|
|
char **dest_ptr = &dest;
|
|
|
|
my_strapp(src, dest_ptr); // Hello, World!
|
|
printf("%s", *dest_ptr);
|
|
free(src);
|
|
free(dest);
|
|
}*/
|