You are missing a NUL
terminating character. You need to allocate one additional character for flipped
and add a '\0'
at the end explicitly.
char* return_flipped_string(char* stringptr)
{
int i=0,size_of_string=length_of_string(stringptr);
char *flipped;
flipped=(char *)malloc((size_of_string + 1)*sizeof(char));
while(i<size_of_string)
{
*(flipped+i)=*(stringptr+size_of_string-1-i);
i++;
}
*(flipped+1) = '\0';
return flipped;
}
BTW - you are aware of the strlen
function in the Standard Library right? Your length_of_string
function duplicates it. I can't remember if strrev
is in the ANSI/ISO Standard or not.