Hello... I may have a fairly simple question, and if so I apologize.
However, I haven't been able to discern or find a solution, so here goes:
I have a program which needs to create a set of files: "values.1","values.2","values.3"
However, then number of such files cannot be hardcoded (as it is defined at runtime as the number of processors I chose to run on), and so the names of these files cannot be hardcoded into the source either.
As such, I want to do the following (where the line I cannot do is sketched (but not correct)). The wrapping lines are included in case the context matters.
Code:
FILE *fout; /* Yes, I do usually do C++, but can't in this instance */
int Np = 4; /* this is the value that cannot be hardcoded */
int i;
char path[32] = "./values.";
char filename[32];
/* The FOR loop is not actually part of the code, but that's MPI specific,
and if I can make it work in this case, I'm (1-eps) sure
that I can make it work in the real code */
for (i=0;i<Np;i++) {
strcpy(filename,path);
strcat( filename, (char *) i ); /* THIS LINE SEEMS TO BE WRONG ... */
fout = fopen(filename,"w"); /* THIS MAY WELL BE WRONG TOO... */
fprintf(fout,"somestuff",somevalues);
fclose(fout);
} /* endfor */
When I try to run this, it compiles, but I do get a warning:
PGC-W-0155-Pointer value created from a nonlong integral type (test.c: 112)
And when I try to run it, I get the error:
p0_20484: p4_error: interrupt SIGSEGV: 11
Any help would be much appreciated on this problem, thank you in advance.