I should solve the following problem by creating a function for reading, one for calculation and use pointers.
#include<stdio.h>#include<stdlib.h>#include<math.h>structponto{intx;inty;}ponto1,ponto2;structponto*p1,*p2;p1=&ponto1;p2=&ponto2;voidler(structponto*p1,*p2){printf("Digite o valor de X1: ");
fflush(stdin);
scanf("%d", &p1 -> x);
printf("Digite o valor de Y1: ");
fflush(stdin);
scanf("%d", &p1 -> y);
printf("Digite o valor de X1: ");
fflush(stdin);
scanf("%d", &p2 -> x);
printf("Digite o valor de Y1: ");
fflush(stdin);
scanf("%d", &p2 -> y);
}
int calculo(struct ponto *p1, *p2)
{
int a, b, d;
a = (*p1).x - (*p2).x;
b = (*p1).y - (*p2).y;
d = sqrt(pow(a,2)+pow(b,2));
printf("%d", d);
}
int main()
{
ler(struct ponto *p1, *p2);
calculo(struct ponto *p1, *p2);
return 0;
}
But I've tried it in so many different ways and it still has the same errors. It's them;
||=== Build file: "no target" in "no project" (compiler: unknown) ===|
|11|warning: data definition has no type or storage class|
|11|warning: type defaults to 'int' in declaration of 'p1' [-Wimplicit-int]|
|11|error: conflicting types for 'p1'|
|10|note: previous declaration of 'p1' was here|
|11|warning: initialization makes integer from pointer without a cast [-Wint-conversion]|
|12|warning: data definition has no type or storage class|
|12|warning: type defaults to 'int' in declaration of 'p2' [-Wimplicit-int]|
|12|error: conflicting types for 'p2'|
|10|note: previous declaration of 'p2' was here|
|12|warning: initialization makes integer from pointer without a cast [-Wint-conversion]|
|14|error: expected declaration specifiers or '...' before '*' token|
|30|error: expected declaration specifiers or '...' before '*' token|
||In function 'main':|
|43|warning: implicit declaration of function 'ler' [-Wimplicit-function-declaration]|
|43|error: expected expression before 'struct'|
|44|warning: implicit declaration of function 'calculo' [-Wimplicit-function-declaration]|
|44|error: expected expression before 'struct'|
||=== Build failed: 6 error(s), 8 warning(s) (0 minute(s), 0 second(s)) ===|