From df4ab3148ee0f88ccc944aa40b521b313a88d5f6 Mon Sep 17 00:00:00 2001 From: "flyingscorpio@pinebookpro" Date: Tue, 2 Nov 2021 16:07:47 +0100 Subject: [PATCH] Add mirroir --- .gitignore | 1 + programmation-c-cpp/tp3/mirroir.c | 41 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 programmation-c-cpp/tp3/mirroir.c diff --git a/.gitignore b/.gitignore index f08888d..dbe821a 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ addition-matricielle strings carte-identite conversion-majuscule +mirroir diff --git a/programmation-c-cpp/tp3/mirroir.c b/programmation-c-cpp/tp3/mirroir.c new file mode 100644 index 0000000..f4ba2c3 --- /dev/null +++ b/programmation-c-cpp/tp3/mirroir.c @@ -0,0 +1,41 @@ +/* Mirroir */ + +#include +#include +#include + + +void mirroir(char*, char*); + +int main() { + char phrase[100]; + char phrase_mirroir[100]; + int i = 0; + + printf("Entrez une phrase : "); + fgets(phrase, 100, stdin); + while (phrase[i] != '\n') { + i++; + } + phrase[i] = '\0'; + + mirroir(phrase, phrase_mirroir); + printf("%s | %s\n", phrase, phrase_mirroir); + + return 0; +} + +void mirroir(char *phrase, char *phrase_mirroir) { + int len_phrase = strlen(phrase); + int j = len_phrase; + + for (int i = 0; i < len_phrase + 1; i++) { + phrase_mirroir[i] = phrase[j]; + printf("%c", phrase_mirroir[i]); + j--; + } + phrase_mirroir[len_phrase] = '\0'; + // TODO: finir + + printf("%s | %s\n", phrase, phrase_mirroir); +}