I though setting up a veritable len
with strlen()
function to find the last char, print it, and then decrement it by 1. It is not working in my code:
#include <stdio.h>
#include <string.h>
#define SIZE 4
int main(void)
{
int index;
char wordToPrint[SIZE];
printf("please enter a random word:\n");
for (index = 0; index < SIZE; index++)
{
scanf("%c", &wordToPrint[index]);
}
int len = strlen(wordToPrint);
for (index = 0; index < SIZE; index++)
{
printf("%c", wordToPrint[len]);
--len;
}
return 0;
}
input is "nir"
output is:
??
r
What is wrong in the last block?
tnx