0
I am trying to get the following output if the imput be: hi mom the output sera: eam io
the code I made, trying to train recursion was:
#include <stdio.h>
void reverse(char *arr)
{
if (*arr != EOF)
reverse((arr + 1));
printf("%c", *arr);
}
int main()
{
char input;
scanf("%s[^\n]", &input);
reverse(&input);
return (0);
}
works for the first word, but returns a strange result after giving a space;
Can anyone explain to me why?
Perfect! Thank you very much, if I may, I’d like to ask you a few questions. Because the Voce input does not need to pass the symbol &? which represents %29 before [ n]s ?
– Piero
@Piero You don’t need to pass the
&
because the array ofchar
works as if it were already a pointer. It has the%29
to ensure that only le 29 characters of the entry for the array as you have to reserve one for the terminator. If I read more than 29, I’d be overwriting the memory that it wasn’t yours.– Isac