So I am learning pointers and i think I mostly understand how they work but Im still learning how to use them correctly.
I wrote this code that receives a pointer to a list with pointers innit, each pointing to a struct called Data. I wanted to organize them by number, like say i have [29-10, 28-10, 3-1] the outcome would be [ 3-1; 2-10; 29-10 ]
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int dia;
int mes;
} Data;
void organiza(Data** l, int n)
{
Data* aux, d1, d2;
int j, i;
for (i = 0;i<n-1;i++ )
{
for (j= i + 1;j<n;j++)
{
d1 = l[i];
d2 = l[j];
if (d1->mes > d2-> mes || (d1->mes == d2-> mes && d1->dia >= d2-> dia ))
{
aux == d1;
d1 == d2;
d2 == aux;
}
}
}
}
While doing so I got a lot of errors which I dont understand why are happening:
error: incompatible types when assigning to type ‘Data’ {aka ‘struct ’} from type ‘Data *’ {aka ‘struct *’}
d1 = l[i];
error: invalid type argument of ‘->’ (have ‘Data’ {aka ‘struct ’})
if (d1->mes > d2-> mes || (d1->mes == d2-> mes && d1->dia >= d2-> dia ))