I'm using int x; to return the value (0 or 1) from system(cmd); command. However, it always returns 0. Any idea's? Here's the code:
Code:
#include <iostream>
using namespace std;
int main(void)
{
char cmd[100];
int ip_a, ip_b, ip_c, ip_d, i, x;
printf("IP Address: ");
scanf("%d.%d.%d.%d", &ip_a, &ip_b, &ip_c, &ip_d);
if (ip_a < 0 || ip_a > 255) return 0;
if (ip_b < 0 || ip_b > 255) return 0;
if (ip_c < 0 || ip_c > 255) return 0;
if (ip_d < 0 || ip_d > 255) return 0;
for ( i = 0; i < 4; i++ ) {
sprintf(cmd, "ping %d.%d.%d.%d -n 1 > nul", ip_a, ip_b, ip_c, ip_d);
x = system(cmd);
printf("X-Value = %d\n", x);
}
system("pause > nul");
return 0;
}