That doesn't explain why there would be a runtime error. It would explain why garbage is displayed and if I modify the program to add
Code:
for (i=0; i<100; i++)
str[i]='~';
to main just after the int i declaration, the output is:
Enter to reverse : hello
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ olleh
but even without this modification I don't get a runtime error (in Visual Studio 2008 building the program in Debug mode).
When it prompted you to enter a string, did you enter more than 100 characters? That might cause a runtime error - this is the infamous "buffer overflow" bug.
If not then I can only suggest this is a compiler bug. Maybe the RTL has a problem with %c for non-printable characters. You can test this hypothesis with a simple program:
Code:
printf("Starting test\n");
fflush(stdout);
for (i=0; i<256; i++)
{
printf("%d %c ",i,i);
fflush(stdout);
}
The fflush ensures that the last character before the runtime error is displayed; normally output is buffered which can cause confusion when a program crashes - it looks like it crashed before it actually went tits up.