I am trying to create a duplicate of a string but reversed. I am able to strcpy each char and print them individually but I get nothing when I print the entire duplicate string.
#include <unistd.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
char str[101] = "Lieur a Rueil";
char temp[101];
int i;
int j;
i = 0;
j = strlen(str);
while (str[j] - 1)
{
strcpy(&temp[i], &str[j]);
printf("%c", temp[i]);
j--;
i++;
}
printf("\n");
printf("temp: %s\n", temp);
return (0);
}
output:
lieuR a rueiL
temp: