I'm trying to write a program to reverse a string, letter by letter. This was my latest attempt:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char oldMsg[100], newMsg[100];
int cd = 12, cu = 0;
strcpy(newMsg, "Hello World!");
while (cd > 0)
{
newMsg[cu] = oldMsg[cd];
cu++;
cd--;
}
printf("%c", newMsg);
printf("\n\nPress ENTER to end . . .");
getchar();
return 0;
}
The final message is a 'p', which I'm not sure where it came from. Can I get some help please?