Hi, could someone explain why I am getting two different values in the code below please?
So if I enter 23 at the prompt I get the follwoing output:Code:#import <stdio.h> #import <string.h> int main (int argc, const char *argv[]) { int inputLength; char userInput[10]; printf("Enter a number to be reversed: "); scanf("%s", &userInput); inputLength = strlen(userInput); printf("inputLength = %i\n\n", inputLength); char computerOutput[inputLength]; printf("\n\ncomputerOutput length = %i", strlen(computerOutput)); printf("\n\nYour entry of %s is %i characters long.\n\n", userInput, inputLength); for (int x = inputLength-1, y = 0; x >= 0; --x, ++y) computerOutput[y] = userInput[x]; printf("computerOutput = %s\n\n", computerOutput); }
inputLength = 2 (yep this is what I expected)
computerOutput length = 21 (What? where is 21 coming from? it should be 2)
Your entry of 23 is 2 characters long. (yep this is what I expected)
computerOutput = 32??????hw???c? (this is 15 long not 21)
I am obviously missing the plot here?
Can someone help please?
Thanks


