Hello there. I tried to do as you said matsp but I didn't manage. I am not sure how to do what you say:
Code:
you need to set the FIRST character of your array to whatever you want to call the file, and the second entry to 0. That way, you have a string of 1 character. You are currently setting position "i" in the array to the letter - that is not right.
I tried to do it a different way using pointers, but I get the same result:
Code:
int file_generator(int number)
{
char newfile[6] = {"TomB"};
char ch = 'a';
char *nfP;
nfP = &newfile;
FILE *nf;
int i=0;
for(i;i<=number;i++)
{
printf("%c\n", *nfP);
nf = fopen(nfP, "w");
nfP++;
if (nf == NULL) {
fprintf(stderr, "Can't open created file %s!\n",
nfP);
exit(1);
}
if (nf == NULL) {
fclose(nf);
}
}
}
which yields:
Code:
B file file.c mB omB TomB
I feel like I am digging my own TomB here!