From 9bbd6f7a7951ac2d420d82f271ab11ce2442d0ca Mon Sep 17 00:00:00 2001 From: "jerome.maison" <jerome.maison@etu.hesge.ch> Date: Tue, 24 Jan 2023 15:52:14 +0100 Subject: [PATCH] exo2 --- exo2/Makefile | 2 +- exo2/exo2.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/exo2/Makefile b/exo2/Makefile index c76c707..b672233 100644 --- a/exo2/Makefile +++ b/exo2/Makefile @@ -8,7 +8,7 @@ LDFLAGS:=-lm exo2: exo2.c - $(CC) $(CFLAGS) -c $@ $^ $(LDFLAGS) + $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) clean: rm -f *.o exo2 diff --git a/exo2/exo2.c b/exo2/exo2.c index e69de29..2c126b6 100644 --- a/exo2/exo2.c +++ b/exo2/exo2.c @@ -0,0 +1,44 @@ +#include <stdio.h> +#include <stdlib.h> + +char fuse_tab(int s1, int s2, char *chain1, char *chaine2); + +int main() { + int s1 = 8; + int s2 = 5; + char chaine1[s1]; + chaine1[0] = 'O'; + chaine1[1] = 'r'; + chaine1[2] = 'e'; + chaine1[3] = 's'; + chaine1[4] = 't'; + chaine1[5] = 'i'; + chaine1[6] = 's'; + chaine1[7] = '\0'; + char chaine2[s2]; + chaine2[0] = 'P'; + chaine2[1] = 'a'; + chaine2[2] = 'u'; + chaine2[3] = 'l'; + chaine2[4] = '\0'; + char out_chaine[s1 + s2]; + out_chaine[s1 + s2] = fuse_tab(8, 5, chaine1[8], chaine2[5]); + for(int i = 0; i < (s1 + s2); ++i){ + printf("%c", out_chaine[i]); + } +} + +char fuse_tab(int s1, int s2, char chaine1[s1], char chaine2[s2]){ + int s; + if(s1 < s2){ + s = s1; + }else{ + s = s2; + } + char out_chaine[s1 + s2]; + for(int i = 0; i < s; i += 2){ + out_chaine[i] = chaine1[i]; + out_chaine[i + 1] = chaine2[i]; + } + return out_chaine[s1 + s2]; +} \ No newline at end of file -- GitLab