Chrax |
12-22-2004 10:51 PM |
C character appending
So I'm making several files, file.1, file.2, all the way up to file.n, and they're going to be created as I reach a certain point in a loop. For example, each time we run through the loop we're going to write a line to a file. When we get to the 100,000,000th line, we'll start on a new file.
I'm not particularly experienced with strings in C, but what I want to do is keep track of which number I'm on, and then create the file names as needed. Here's the source of what I've tried:
Code:
#include <stdio.h>
#include <gmp.h>
int main(int argc, char **argv)
{
FILE *infile;
FILE *outfile;
mpz_t trans;
mpz_init(trans);
long long count = 0;
int fileno = 49;
infile = fopen("/asdf/primelog","r");
outfile = fopen("/asdf/primelog.1","w");
while(gmp_fscanf(infile,"%Zd",&trans) != EOF){
if(count++ == 100000000){
fileno++;
fclose(outfile);
char *filename = "/asdf/primelog." + fileno;
outfile = fopen(filename,"w");
}
gmp_fprintf(outfile,"%Zd\n",trans);
}
fclose(outfile);
}
But C apparently doesn't like + concatenations. How would I go about adding a number on at the end? (For the moment, I'm assuming we're not going multidigit. That shouldn't be too much of a problem once I've got this bit.)
|