Hello guys,
Sorry for my bad english I'm from Brazil, let's go...
I was trying to create a code that reverses the string in C, but I don't understand why that code does not work.
Can you guys help me?
Thanks a lot!
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char* reversestring(char* stringt){
int len = strlen(stringt);
char *ret = malloc(len * sizeof(char));
int i = 0;
int count;
for(count = len;count > 0;--count){
ret[i++] = stringt[count];
}
return ret;
free(ret);
}
int main(){
printf("%s",reversestring("teste"));
}