This commit is contained in:
2026-02-02 04:52:09 +01:00
parent fca4d20f5a
commit 49213b1343
6 changed files with 64 additions and 54 deletions
+9 -6
View File
@@ -7,7 +7,8 @@ char *strdup(const char *s);
void my_strapp(char *src, char **dest){
if (src == NULL || dest == NULL) return;
if (*dest == NULL) return;
//taille src
int index = 0;
while (*(src + index)) index ++;
@@ -17,10 +18,11 @@ void my_strapp(char *src, char **dest){
while (*(*dest + index_dest)) index_dest ++;
//realloc des dest avec la taille de src
*dest = realloc(*dest, index + index_dest + 1);
char *new = realloc(*dest, (index + index_dest + 1) * sizeof(char)) ;
//int *dest = realloc(*dest, index);
if (dest == NULL) return;
if(new == NULL) return;
*dest = new;
index = 0;
/*while(*(new + index_dest)){
@@ -42,19 +44,20 @@ void my_strapp(char *src, char **dest){
index ++;
}
*(dest + index_dest + index + 1) = '\0';
*(*dest + index_dest + index) = '\0';
}
/*
int main(){
char *src = strdup("World!");
char *dest = strdup("Hello, ");
//char *dest = '\0';
char **dest_ptr = &dest;
my_strapp(src, dest_ptr); // Hello, World!
printf("%s", *dest_ptr);
free(src);
free(dest);
}*/
}