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 04:54:21 +01:00

64 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;
if (*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
char *new = realloc(*dest, (index + index_dest + 1) * sizeof(char)) ;
//int *dest = realloc(*dest, index);
if(new == NULL) return;
*dest = new;
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) = '\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);
}*/