efrei/programmation-c-cpp/tp3/mirroir.c

33 lines
614 B
C
Raw Normal View History

2021-11-02 16:07:47 +01:00
/* 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);
2021-11-02 22:37:37 +01:00
while (phrase[i] != '\n') i++;
2021-11-02 16:07:47 +01:00
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);
2021-11-02 22:37:37 +01:00
for (int i = 0; phrase[i] != '\0'; i++) {
phrase_mirroir[i] = phrase[len_phrase - 1 - i];
2021-11-02 16:07:47 +01:00
}
}