0

So I'm coding in C for a list of IP addresses, listed one above the other in a .txt file, which should be read, and simultaneously pinging them one by one. Now, my main concern is to select which ones are available and respond to the ping. A friend suggested redirecting the stdout to a .txt file, browsing through it and listing those unavailable with "(!=)". To be honest, still with his advice I don't find the way to do so. So far I've been able to redirect the results to a .txt, namely "out.txt". Is there a way to browse through it and how could I retrieve the IP's whose received packages are different than 0?

Many, many thanks to whoever helps me with this task.

This is what I've so far:

FILE* fp;
char ch[500], x[225], str[80];

printf("\n    Escribe la ruta del documento deseado\n\n");
scanf("%s", x);

fp = fopen(x, "r");
freopen("out.txt", "a", stdout);

if (fp == NULL)
{
    printf("El archivo no se ha podido encontrar.");
    exit(0);
}

while (fgets(ch, 100, fp)) {
    printf("%s", ch);
}
        rewind(fp);

        while (!feof(fp)) {
            fgets(ch, 100, fp);
            strcpy(str, "ping ");
            strcat(str, ch);
            system(str);
        }

0 Answers0