I currently have a problem with this code. The problem is that I don't know the problem. I've checked it over and over again and found nothing. Debugging only tells me that is is stuck on the 'while (run ==1)' line. I find no reason for that to be the case. The testing 'printf' I wrote right after that 'while' does not run. I'm beyond confused with this. I've already used some means to verify that the data inside the list is correct.
I would appreciate if someone could help me, but please point me towards the right direction, don't outright give me the code as I'd rather not be accused of plagiarism.
EDIT: I am the one idiot to rule them all. And probably blind too. Problem has been found. I hope.
These are the data types I'm using:
Code:
typedef struct
{
float angle;
int hemisferio;
} geo_coord;
typedef struct
{
int dia;
int mes;
int ano;
} data;
typedef struct
{
data dt;
float temperatura;
float incerteza;
char pais[100];
char cidade[100];
geo_coord lat;
geo_coord lon;
} dados_temp;
typedef struct
{
int ind;
float temperaturamed;
float temperaturamax;
float temperaturamin;
char nome[100];
} data_temp_a;
typedef struct node
{
dados_temp payload;
struct node *next;
struct node *prev;
} node_t;
Code:
void temp_a(node_t *_list, int mode, int anot)
{
int n = 0, ttest = 1, s = 0, i = 0, it = 0, loop = 0, run = 1;
char choice[100];
char *test = NULL;
printf("Por favor insira o número de dados que quer analisar (1 a 20): ");
while (ttest == 1)
{
fgets(choice, 100, stdin);
choice[strlen(choice)-1] = '\0';
ttest = ContainAlpha(choice);
if (ttest == 0)
{
n = atoi(choice);
}
if (n < 1 || n > 20)
{
printf("Erro. Número fora dos limites aceitáveis. ");
ttest = 1;
}
}
data_temp_a *store = NULL;
store = (data_temp_a *)malloc(sizeof(data_temp_a));
_list = rewindList(_list);
while (run == 1);
{
printf("Cycle %d\n", i);
if (s == 0)
{
if (_list->payload.dt.ano == anot)
{
store[0].ind = 1;
store[0].temperaturamax = _list->payload.temperatura;
store[0].temperaturamin = _list->payload.temperatura;
store[0].temperaturamed = _list->payload.temperatura;
if (mode == 0)
{
strcpy(store[0].nome, _list->payload.pais);
}
else
{
strcpy(store[0].nome, _list->payload.cidade);
}
s = 1;
i++;
}
}
else
{
if (_list->payload.dt.ano == anot)
{
for (it = 0; it<i; it++)
{
if (mode == 0)
{
test = strstr(store[it].nome, _list->payload.pais);
}
else
{
test = strstr(store[it].nome, _list->payload.cidade);
}
if (test != NULL)
{
store[it].ind++;
if (_list->payload.temperatura > store[it].temperaturamax)
{
store[it].temperaturamax = _list->payload.temperatura;
}
if (_list->payload.temperatura < store[it].temperaturamin)
{
store[it].temperaturamin = _list->payload.temperatura;
}
store[it].temperaturamed += _list->payload.temperatura;
}
else
{
i++;
store = (data_temp_a *)realloc(store, i*sizeof(data_temp_a));
store[i].ind = 1;
store[i].temperaturamax = _list->payload.temperatura;
store[i].temperaturamin = _list->payload.temperatura;
store[i].temperaturamed = _list->payload.temperatura;
if (mode == 0)
{
strcpy(store[i].nome, _list->payload.pais);
}
else
{
strcpy(store[i].nome, _list->payload.cidade);
}
}
test = NULL;
}
}
}
if (_list->next != NULL)
{
_list = _list->next;
}
else
{
run = 0;
}
}
for (it = 0; it<i; it++)
{
store[it].temperaturamed = store[it].temperaturamed / (float)store[it].ind;
store[it].temperaturamax = store[it].temperaturamax - store[it].temperaturamin;
}
qsort(store, i, sizeof(data_temp_a), (compfn)comparisonext);
printf("%d locais com temperaturas mais extremas:\n", n);
for (it = 0; it < n; it++)
{
printf("%s : %f\n", store[it].nome, store[it].temperaturamax);
}
qsort(store, i, sizeof(data_temp_a), (compfn)comparisonmed);
printf("%d locais com temperaturas mais altas:\n", n);
for(it = 0; it < n; it++)
{
printf("%s : %f\n", store[it].nome, store[it].temperaturamed);
}
printf("%d locais com temperaturas mais baixas:\n", n);
for(it = i-1; it > it-20; it++)
{
printf("%s : %f\n", store[it].nome, store[it].temperaturamed);
}
while (loop == 0)
{}
free(store);
}