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-03-2030/AcquiringLand/Fundamentals/join_strings.c
T
2026-02-09 03:43:16 +01:00

58 lines
1.2 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
char *join_strings(char *strings[], int count){
if (strings == NULL) return NULL;
int tot = 0;
int index = 0;
//connaitre taille des str dans strings
for (int i = 0; i < count; i++){
index = 0;
//binf
while (strings[i][index]){
tot ++;
index ++;
//printf("boucle inf ici");
}
}
char *rslt = malloc((tot + count) * sizeof(char));
if (rslt == NULL) return NULL;
tot = 0;
for (int i = 0; i < count; i ++){
index = 0;
//binf
while (strings[i][index]){
*(rslt + tot) = strings[i][index];
index ++;
tot ++;
}
if (i == count - 1)
*(rslt + tot) = '\0';
else *(rslt + tot) = ' ';
tot ++;
}
//free(strings);
return rslt;
}
/*
int main(){
char *str[] = {"Hello", "from ", "Java", "swimming pool"};
char *test = join_strings(str, 4);
printf("%s\n", test);
free (test);
test = join_strings(NULL, 0);
printf("%s\n", test);
free(test);
}*/