String printing problem

0

I would like to know the problem of my string inside the function, it goes through the string and when I find an uppercase letter turn it to lowercase (I already tried to use tolower and isupper , but it did not work) and when find a point, exclamation, interrogation, colon and semicolon should replace them with a space and return it to main, but it is not being altered, here is the code below:

char* diminuieretira(char** p, int r)//Declaração de função que converte as letras maiusculas em minusculas e adiciona no lugar das pontuações o espaço
{
    int i = 0;

    for(i = 0; i < r; i++)
    {

        if((*p[i]) >= 65 && (*p[i]) <= 90) //Se o caracter for maisculo
            (*p[i]) + 32; //Converto-o para minusculo

        else if((*p[i]) == 46 || (*p[i]) == 44 || (*p[i]) == 59 || (*p[i]) == 58 || (*p[i]) == 33 || (*p[i]) == 63); //Se o caracter for um ponto de exclamação, ponto, interrogação, dois pontos ou ponto e virgula
            (*p[i]) = 32; //Essa pontuação é substituida por um espaço
    }

    printf("%s", (*p)); //Imprimo na tela a strign modificada

    return (*p); //Retorno para a main a string modificada
}
    
asked by anonymous 11.06.2015 / 04:02

2 answers

1

(*p[i]) + 32; does nothing - this command adds 32 to (*p[i]) , but does nothing with the result. You want

*p[i] = *p[i] + 32;

(parentheses are unnecessary) or, more succinctly

*p[i] += 32;
    
11.06.2015 / 04:05
0

You do not need to use char** p in this function, you can only use char* p , since you are only working over a string. Using char** p will make your function more confusing. And, unless you want to modify only part of the string, you also do not need to pass the string size ( int r ), you can use the strlen function in your for.

Your code (*p[i]) + 32 does not change the value of *p[i] , since there is no equal sign. He does not do anything. And since you're using a double pointer ( char** ), it would be good to write as (*p)[i] , since * can refer to p or p[i] . You need to change to: (*p)[i] = (*p)[i] + 32

And as @ctgPi said, you can put the symbols directly to make your code more readable (or put a comment next to it). So its function would look like this:

char* diminuieretira(char* p)//Declaração de função que converte as letras maiusculas em minusculas e adiciona no lugar das pontuações o espaço
{
    int i = 0;

    for(i = 0; i < strlen(p); i++)
    {

        if(p[i] >= 65 && p[i] <= 90) //Se o caracter for maisculo
            p[i] += 32; //Converto-o para minusculo

        else if(p[i] == '.' || p[i] == ',' || p[i] == ';' || p[i] == ':' || p[i] == '!' || p[i] == '?'); //Se o caracter for um ponto de exclamação, ponto, interrogação, dois pontos ou ponto e virgula
            p[i] = ' '; //Essa pontuação é substituida por um espaço
    }

    printf("%s", p); //Imprimo na tela a strign modificada

    return p; //Retorno para a main a string modificada
}
    
11.06.2015 / 17:22