This repository has been archived on 2026-05-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
prog-103-p-02-2030/Digby_Real_Estate/Fundamentals/my_strapp.c
T
2026-02-02 03:36:21 +01:00

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);
}*/