I'm having some trouble coding in C an iteration, that's to be taken from a .txt file where there are several IP's listed one above the other in several lines. What I need to do is to print the whole content of the file and immediately after, ping each one of the IP's automatically, one after the other. I've been struggling for some hours and I'm unable to get it - I have no idea for the iteration, and so far I've only been able to print the actual file but it just pings the 2nd line instead of the first one.
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");
if (fp == NULL)
{
printf("El archivo no se ha podido encontrar.");
exit(0);
}
while (fgets(ch, 100, fp)) {
printf("%s", ch);
}
fgets(ch, 100, fp);
strcpy(str, "ping ");
strcat(str, ch);
system(str);
}
Any help? Thanks in advance.