-1
I created a simple code with the function void
where there is a passage by reference. However, it is giving the following error when compiling:
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;
}
You should get a
char *a
, instead ofchar **a
. just need to change that. If you are going to receive a char through pointer, then you have to define that way– Fábio Morais