I'm beggining to learn C but i'm stuck in this exercise, i have to implement a function that reverses a string (in place) and i really don't know what i'm doing wrong. Any help will be welcome, thanks!
#include <stdio.h>
#include <string.h>
void invertir(char* cadena){
char aux;
int i = 0;
int j = strlen(cadena) / 2;
while(i < j){
aux = cadena[i];
cadena[i] = cadena[j];
cadena[j] = aux;
i++;
j--;
}
printf("La palabra invertida es: %s\n",cadena );
}
void main(){
return invertir("parlante");
}
it gives me 'segmentation fault', i'm sure it's a rookie mistake or something i forget to do. so thanks for the patience!