I'm trying to reverse a string without using a temp string, but when I execute the program I have olllo
as result not olleH
.
Here is my code:
#include <stdio.h>
#include <string.h>
int main(){
char *str = strdup("Hello");
int reverse(char * str){
int i=0;
int j = strlen(str)-1;
while(i<=j){
(str[i]) = (str[j]);
i++;
j--;
}
return 0;
}
reverse(str);
printf("string = %s\n", str);
return 0;
}