You need format the string to put the value of the variable inside it. You can even concatenate string, but it’s a scam*.
I wouldn’t make a loop infinite, just a big one. It’s not to have performance or memory problems, but there will be problems when it goes over 2 billion and little and would have to treat that, then it starts to complicate the algorithm, and if it’s to complicate, it’s not to do any of this.
If you need a bigger number, use a long
or long long
in place of int
, with its due limit.
#include <stdio.h>
#include <limits.h>
int main() {
int i = 0;
while (i < INT_MAX) {
char buffer[100] = "";
sprintf(buffer, "pathping xxx.xxx.xxx.xxx > %d.txt\n", i++);
system(buffer);
}
}
I made a ideone slightly modified because I am not allowed to run the system()`. And yes, it is dangerous. And put on the repl it.. Also put on the Github for future reference.
Maybe take a break (Sleep or timer) between one step and another is a good idea.
Exactly what I was looking for! Thank you! Although it is an infinite loop I believe it will not reach the billions but vlw by tip!
– Lucas