5
I’m doing a C algorithm to shut down 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 the line system("shutdown -m 192.168.2.200 -s -f \n");
I need to replace the ip with mine vetor[i]
, but the system command only accepts one parameter.
How can I make that concatenation?
Guys. I tested the options that passed 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);
}
consider marking one of the answers as accepted.
– lazyFox
You did ua second question that has nothing in common with the theme of the first. Please put it as a separate question, and mark an accepted answer to the original question.
– jsbueno