Change an array of char within a function

0

I'm trying to pass a char array pointer to a function. I want it to make changes to this char array.

Here is the code for the function:

void dhnfe( char tzd, char hverao, char *dh)
{
    if (hverao == 1)
    {

        switdh(tzd)
        {
        case -2: /*Fuso de Fernando de Noronha */
            dh = "%Y-%m-%d-T-%H:%M:%S-2:00";
            break;
        case -3: /*Fuso de Brasilia*/
        default:
            dh = "%Y-%m-%d-T-%H:%M:%S-3:00";
            break;
        case -4: /*Fuso de manaus*/
            dh = "%Y-%m-%d-T-%H:%M:%S-4:00";
            break;
        }
    }
    else if (hverao == 0)
    {
        switdh(tzd)
        {
        case -2: /*Fuso de Fernando de Noronha Horario de Verao*/
            dh = "%Y-%m-%d-T-%H:%M:%S-1:00";
            break;
        case -3: /*Fuso de Brasilia Horario de Verao*/
        default:
            dh = "%Y-%m-%d-T-%H:%M:%S-2:00";
            break;
        case -4: /*Fuso de Manaus Hoario de Verao*/
            dh = "%Y-%m-%d-T-%H:%M:%S-3:00";
            break;
        }
    }
}
    
asked by anonymous 24.06.2017 / 20:45

1 answer

0

What I wanted was to change the dh string that passed as a parameter in the function. At the time I passed as * dh instead of ** dh / * dh [].

This code changes the string in two different ways (for didactic purposes), by return and within the function.

  static char  *dhnfe(signed char tzd,signed char hverao,char **dh){
char *aux;

if (hverao == 1){

    switch (tzd){
        case -2: /*Fuso de Fernando de Noronha */
            aux = "%Y-%m-%d-T-%H:%M:%S-2:00";
            break;
        case -3:/*Fuso de Brasilia*/
        default:        
            aux = "%Y-%m-%d-T-%H:%M:%S-3:00";
            break;
        case -4:/*Fuso de manaus*/
            aux = "%Y-%m-%d-T-%H:%M:%S-4:00";
            break;
    }
}else if(hverao == 0){
    switch (tzd){
        case -2:/*Fuso de Fernando de Noronha Horario de Verao*/
            aux = "%Y-%m-%d-T-%H:%M:%S-1:00";
            break;
        case -3:/*Fuso de Brasilia Horario de Verao*/
        default:        
            aux = "%Y-%m-%d-T-%H:%M:%S-2:00";
            break;
        case -4:/*Fuso de Manaus Hoario de Verao*/
            aux = "%Y-%m-%d-T-%H:%M:%S-3:00";
            break;
    }
}
*dh = aux;
return aux;

}

    
07.02.2018 / 02:17