0

My main suspicion is that i am meant to null terminate the string i'm returning or is it already terminated ?. Here's my code:

#include <stdio.h>
#include <string.h>
#include <math.h>

char* reverse(char*);


int main(void) {

printf("%s",reverse("abcde"));
return 0;
}

char* reverse(char* string){
  int length = strlen(string);
  int limit = (int)floor(length/2);
  char temp;

for(int x = 0;x<=limit;x++){
    temp = string[x];
    string[x] = string[length-x-1];
    string[length-x-1] = temp;

}

return string;


}
simdi ejinkeonye
  • 111
  • 1
  • 1
  • 7

0 Answers0