If you had tried to use a debugger, you would see that t is going mad on second iteration. This is because after you have copied string into b you forgot to insert \0 symbol at the end (position with index t-1). This causes t become literally anything on the next iteration because of strlen() needs a null-terminating string and it results in an undefined behaviour as mentioned in docs:
The behavior is undefined if str is not a pointer to a null-terminated
byte string
So a quick fix is as folows:
...
for (int i=0;i<t-1;i++)
{
b[i]=string[i];
}
b[t-1] = '\0';
reverse(b);
...
And as already mentioned in comments by @LPs : change scanf("%s",&a); to scanf("%199s",a); (199 because we need to leave a space for '\0' at the end, thanks to @RoadRunner for noticing that)
Note: take a look at strncpy_s (if you use C11) and use it instead of that for loop:
printf("%c",string[t-1]);
strncpy_s(b, 200, string, t-1); // 200 because char b[200]
reverse(b);
or strncpy:
printf("%c",string[t-1]);
strncpy(b, string, t-1);
b[t-1] = '\0';
reverse(b);
Still another approach is not to copy:
else
{
string[t-1] = '\0'; // you don't need array 'b' at all
reverse(string);
}
And the simpliest way is just to use a loop:
for (int i = strlen(string) - 1; i >= 0; --i)
{
printf("%c", string[i]);
}
{printf(...