Invalid operands of types 'char' and 'char *' to binary 'operator *'?

0

I did this function in c ++ to invert a word

void cambio(char*); //cadena a ingresar
void cambio(char *v){
int d=strlen(v); //dimensión de la cadena
int e= d-1; // valor para leer la cadena desde el último carácter
char temp; // variable temporal
for(int i=0; i<(d/2); i++){
    temp= *(v+i)
    *(v+i) = *(v+(e+i)); //el error me lo produce en esta línea
    *(v+(e+i))=temp; 

}
return;
}

help: (

    
asked by justAprogrammer 03.11.2016 в 02:31
source

1 answer

0

You forget the semicolon:

void cambio(char *v){
int d=strlen(v); //dimensión de la cadena
int e= d-1; // valor para leer la cadena desde el último carácter
char temp; // variable temporal
for(int i=0; i<(d/2); i++){
    temp= *(v+i); // <= Aquí
    *(v+i) = *(v+(e+i)); //el error me lo produce en esta línea
    *(v+(e+i))=temp; 

}
return;
}

Anyway, apart from not being necessary to declare the function if you define it afterwards, you do not need to deal with pointer arithmetic constantly, you can use the operator [] :

void cambio(char *v) {

    int d = strlen(v);
    char temp; // variable temporal

    for(int i = 0; i < (d / 2); ++i) { // ++i mejor que i++
        temp = v[i];
        v[i] = v[d + i - 1];
        v[d + i - 1] = temp;
    }

    // return; // No necesitas poner 'return' en una funcion 'void'.
} 
    
answered by 03.11.2016 / 02:40
source