Double posted and asked some further nonsense, haha. Sorry for the hassle.
Now, after having spent my time modularizing the whole program, my main looks like this:
Code:
int main()
{
FILE* fp;
{
printf("\n Escribe la ruta del documento deseado: ");
scanf("%s", x);
printf("\n");
fp = fopen(x, "r");
if (fp == NULL)
{
printf("\n El archivo no se ha podido encontrar\n\n");
exit(0);
}
while (fgets(ch, sizeof(ch), fp))
{
printf("%s", ch);
}
printf("\n");
fclose(fp);
leerAdaptadores();
leerIpsValidas();
comparativaIps();
extraerDNS();
comparativaDNS();
}
}
So far, so good.
The DNS extraction works perfect. I've that "dns_responden.txt" filled with the data I need, i.e. DNS lined one after the other with line breaks among them, just like my "ip_responden.txt" file I needed for "comparativaIps()":
Code:
void comparativaIps()
{
int best_response = 0;
char ipresp[100], best_ip[sizeof(ipresp)] = "";
int best_valid = 0;
FILE* responses = fopen("ips_responden.txt", "r");
if (responses != NULL)
{
while (fgets(ipresp, sizeof(ipresp), responses))
{
int response1 = velocidad_media(ipresp);
if (!best_valid || response1 < best_response) {
best_response = response1;
strcpy(best_ip, ipresp);
best_valid = 1;
}
}
printf("\n IP seleccionada: %s", best_ip);
printf("\n Velocidad de respuesta media: %d ms.\n", best_response);
fclose(responses);
}
}
As for the "comparativaDNS()" block, it's just the same as "comparativaIps()" and still unable to print what I expect to do...:
Code:
void comparativaDNS()
{
int best_response_time = 0;
char ip_str[100], best_dns[sizeof(ip_str)] = "";
int best_valid_dns = 0;
FILE* responsesdns = fopen("dns_responden.txt", "r");
if (responsesdns != NULL)
{
while (fgets(ip_str, sizeof(ip_str), responsesdns))
{
int dns1 = velocidad_media(ip_str);
if (!best_valid_dns || dns1 < best_response_time) {
best_response_time = dns1;
strcpy(best_dns, ip_str);
best_valid_dns = 1;
}
}
printf("\n\n Velocidad de respuesta media: %d ms.\n", best_response_time);
printf("\n DNS seleccionada: %s", best_dns);
}
}