TP3 E7
This commit is contained in:
parent
632f73d01f
commit
86f2df33ed
34
TP3/E7.c
Normal file
34
TP3/E7.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
/* Miroir */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define N 255
|
||||
|
||||
int length(char* c) {
|
||||
int i, len = -1;
|
||||
for (i = 0; i < N; i++) {
|
||||
if (c[i] == '\0') {
|
||||
len = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
char* miroir(char* c) {
|
||||
int i, len = length(c);
|
||||
static char mir[N];
|
||||
for (i = 0; i < len; i++) {
|
||||
mir[i] = c[len-i-1];
|
||||
}
|
||||
return mir;
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
char c[N];
|
||||
printf("Entrez du texte : ");
|
||||
scanf("%s", &c);
|
||||
printf("Miroir : %s\n", miroir(c));
|
||||
return 0;
|
||||
}
|
Reference in a new issue