Firstly: your loop is all wrong. With the code you've written above, you're testing whether i==1
, not setting i
to 1. And then your condition for continuing the loop is i==N
, which means it will only continue if that is true. You're presumably aiming for:
for(int i=1; i<=N; i++)
This would operate N times, with values of i
running from 1 to N, inclusive.
One way to do this would be to use sprintf from the C library.
This requires you to create a char array, which will then be filled by sprintf. It takes the array as the first argument, then the string you want to fill it with. You can place tokens in the string indicating the type of variables to be included, and add those variables as subsequent arguments.
For example:
int x=5;
char buffer[50];
sprintf(buffer,"file%d.txt",x);
after the sprintf line is executed, the variable buffer
will hold "file5.txt".
If you place the sprintf line within your loop, then you can of course use the loop index to get what you want.
A fuller tutorial on the usage of sprintf can be found here.