The first thing you do is copy the null terminator of the string into the first position of the array, so it is normal that it prints as an empty string.
void lettreCount(char *saisi, int length){
int i, j = 0;
char revers[length];
for (i = length; i >= 0; --i){ //loop
*(revers+j) = saisi[i];
The first character you copy is saisi[length]
--> revers[0]
, so you put a '\0'
at the start of your string.
void lettreCount(char *saisi, int length){
char revers[length];
int i = length, j = 0;
while (--i >= 0) { //loop
revers[j++] = saisi[i];
}
/* you need to end the string */
revers[j] = '\0';
printf("%s\n",revers);
}
Your code corrected is shown below, as you have some other counseils given in the comments:
#include <stdio.h> /* you need also this file to use fgets, gets or printf */
#include <stdlib.h>
#include <string.h>
// ƒ to revers the word
void lettreCount(char *saisi, int length){
char revers[length];
int i = length, j = 0;
while (--i >= 0) { //loop
revers[j++] = saisi[i];
}
/* you need to end the string */
revers[j] = '\0';
printf("%s\n",revers);
}
int main(){
char text[100]; //Array for text
int len;
printf("Saisissez le text:\n");
/* Don't use the obsolete gets, use fgets */
fgets(text, sizeof text, stdin);
len = strlen(text);
lettreCount(text, len);
}