I have a problem, in a code that I found in that it receives a user string and returns it inverted, doing so in a recursive way.
However, I do not understand why the function actually does this.
Follow the code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void recebeString(char *string)
{
if(*string)
{
recebeString(string+1);
putchar(*string);
}
}
int main()
{
char resultado[250];
printf("Escreva uma string(frase): ");
scanf("%[^\n]",resultado); // força o scanf a ler ate encontrar o \n.
setbuf(stdin, NULL);
printf("%s\n\n",resultado);
recebeString(resultado);
return 0;
}
Can anyone help me?