Hmm...
I've been following the values .. and the numbers check out...
I've edited the code so it outputs the value changes.
Code:
void reverser(char input[], char output[])
{
int i, c; //initialize vars
for(i=0; input[i] != '\0'; ++i);// counts length of input
printf("starting value of i :%d\n", i); // tests the result of i
for (c=0;i !=0; ++c){ // for as long as i is not 0 loop & increase c by 1
printf("i=%d c=%d\n", i, c);// tests results of i & c while looping
output[c] = input[i]; // copy input into output
--i; // decrease i by 1
}
output[c+1] = input[i]; //copy final character on array
printf("Final : c = %d i = %d Which makes : %s\n", c, i, output); // test final output
}
When executed it results :
(hello & ^Z are my input)
input or EOF ?
hello
input or EOF ?
^Z
starting value of i :5
i=5 c=0
i=4 c=1
i=3 c=2
i=2 c=3
i=1 c=4
Final : c = 5 i = 0 Which makes :
My analyses of this is:
The values itself are correct so the loops (although it might be done more efficient) do the job right.
The copying of input to output goes wrong though
Code:
output[c] = input[i]; // copy input into output
There... Though the strange thing is .. when I replace the c in output to i ... It DOES copy array content.. Though ofcourse it's not the right output.
Am I analyzing this wrong??