In the code below, I need to create a structure for Point (Coordinate x and y) and create a function that creates those points using pointers. The structure was made as follows:
typedef struct //Estrutura definida para os pontos.
{
double x; //Coordenadas X e Y.
double y;
} Ponto;
Then I created the function to create these points and another function to print these points:
void CriaPonto(Ponto *p, double x, double y) //Função que cria n pontos.
{
p->x = x;
p->y = y;
int i, nponto;
printf("Digite a quantidade de pontos que se quer (Maximo 100): ");
scanf("%d", &nponto);
if(nponto < 1 || nponto > 100)
{
printf("Quantidade de pontos invalida.");
}
else
{
printf("Digite as coordenadas X e Y:\n");
for(i = 0; i < nponto; i++)
{
scanf("%lf", &p[i].x);
scanf("%lf", &p[i].y);
}
printf("\n");
}
}
void ImprimePonto(Ponto P[])
{
int i, nponto;
for(i = 0; i < nponto; i++)
printf("Ponto %d: (%.0lf,%.0lf)\n", i+1, P[i].x, P[i].y);
printf("\n");
}
In the main function (main) of the program I did as follows:
int main()
{
Ponto Ponto[MAX];
int x, y;
CriaPonto(Ponto, x, y);
ImprimePonto(Ponto);
return 0;
}
When compiling I get 3 warnings.
In function 'ImprimePonto'
'nponto' is used uninitialized in this function [-Wuninitialized]|
In function 'main':
'y' is used uninitialized in this function [-Wuninitialized]|
'x' is used uninitialized in this function [-Wuninitialized]|
The questions I have are: Is the way I created the function correct? What do I need to remove these 3 warnings when compiling?