Hello all,
I was trying to practice moving my programs into functions, so they are not only in the main() and also with creating files.
I can create a single file with no problem. However, I could not get my program to succeed with creating multiple files.
I want the program to be able to create say 4 text files each with a unique name and be concatenated with .txt at the end:
text1.txt
..
text4.txt
Could someone point out where I am going wrong please?
Here is the code I have done:
Code:#include<stdio.h> int file_generator(int number); main() { int nrfiles = 4; file_generator(nrfiles); } int file_generator(int number) { FILE *nf; int i=1; char newfile[10]; for(i;i<=number;i++) { newfile[i] = "test"; nf = fopen(newfile[i], "w"); if (nf == NULL) { fprintf(stderr, "Can't open created file %s!\n", newfile); exit(1); } fclose(nf); } }


