Add mirroir
This commit is contained in:
parent
f90b27134b
commit
df4ab3148e
2 changed files with 42 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -30,3 +30,4 @@ addition-matricielle
|
|||
strings
|
||||
carte-identite
|
||||
conversion-majuscule
|
||||
mirroir
|
||||
|
|
41
programmation-c-cpp/tp3/mirroir.c
Normal file
41
programmation-c-cpp/tp3/mirroir.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
/* Mirroir */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
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);
|
||||
}
|
Loading…
Reference in a new issue