I'm doing an algorithm in C to turn off some machines. This is my algorithm:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
main() {
char vetor[2][15] = {"192.168.2.200", "192.168.2.201"};
for(int i = 0; i < 2; i++){
system("shutdown -m 192.168.2.200 -s -f");
}
system("pause");
return 0;
}
But on line system("shutdown -m 192.168.2.200 -s -f \n");
I need to replace ip with my vetor[i]
, but the system command only accepts one parameter.
How can I do this concatenation?
Galera. I have tested the options that have happened to me and it worked. Thank you.
But I have one last question.
If you have 3 IPs in my array
And one of them is inaccessible, can you do a check before running the system? For example:
for(int i = 0; i < 3; i++){
if(vetor[i] == "inacessivel") { //Aqui poderia ser um booleano também, ou int. Coloquei para exemplificar o que desejo fazer
continue;
}
sprintf(str, "shutdown -m %s -s -f", vetor[i]);
system(str);
}