Pointers in C language

-1

I created a simple code with the function void where there is a passage by reference. However, it is giving the following error at compile time:

  

lala.c: In function 'main':

     

lala.c: 19: 12: warning: passing argument 2 of 'test' from incompatible pointer type [-Wincompatible-pointer-types]

     

test (i, & a);

     

^   lala.c: 4: 6: note: expected 'char **' but argument is of type 'char *'

     

void test (float i, char ** a)

     

^ ~~~~

Code:

#include <stdio.h>
#include <stdlib.h>

void teste (float i, char **a)    
{
    if (i<=7)
        *a = "Menor ou igual a sete";
    else    
        *a = "Maior que sete";
}

int main() {
    float i;
    char a;

    printf("Digite o número ");
    scanf("%f", &i);
    teste (i, &a);

    printf("%s\n", a);
    system ("pause");
    return 0;
}
    
asked by anonymous 24.10.2018 / 04:16

1 answer

-1

As quoted in the comments, the teste() function is wrong; use this:

void teste (float i, char *a)
{
    if (i<=7)
        a = "Menor ou igual a sete";
    else
        a = "Maior que sete";
}

Give a searched in subject ( parameters c ), has a lot of useful material like this .

    
24.10.2018 / 13:47