hey when you put in something like system(ping www.example.com);
you don't get any visible results...
anybody know if there is a way to print out the ip address it gets from the ping onto the screen.
If you want to keep the code portable, then you can redirect the output to a file... char buf[BUFSIZ] = { 0 }; sprintf(buf, "ping www.example.com > ping.txt"); system(buf);More than likely, you'll need to pause your app before you'll be able to read the file. You can make a crude timer function by including time.h
void snooze(int sec) { time_t st = time(NULL), et; do { et = time(NULL); } while(et < st + sec); }lastly, read the file back
FILE *fp; // ping the site // pause the app // read back the file if((fp = fopen("test.txt", "r")) != NULL) { memset(buf, 0, sizeof buf); while((fgets(buf, sizeof buf, fp)) != NULL) { char *p = strchr(buf, '\n'); if(p != NULL) { *p = '\0'; } puts(buf); } fclose(fp); }I'm sure there are other ways, but that's what I tend to do. :P
HTH
thanks :)
Or you just do : system("ping www.example.com");
??
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |