I'm new to C programming so there is probably a simple solution for this but I trying to create multiple directories and files within those directories by using a loop in C. For example,
Directory1
- text1.txt
- text2.txt
Directory2
- text1.txt
- text2.txt
I haven't yet implemented the loop but I am trying to append the file name onto the folder so that I can create the file.
I have attached the code and I know that the error is in line 5 where I am trying to concatinate the string. Is there a way to create a variable to store the name of the directory and also append the file name to directory in order to create the file?
Thank you for your help.
Here is the code I have written so far
char folder[] = "directory1/";
mkdir(folder, 0750);
//Create text file in directory
fPointer = fopen(folder + "text.txt", "w");
for(int i = 0; i < textLength; i++){
//Only return numbers from 0 - 25
int rnum = rand() % 26;
//Use uppercase ascii values therefore add 65
text[i] = (char) (rnum +65);
//Write to the file
fprintf(fPointer,"%c",text[i]);
}
//Stop writing to text.txt and close connection
fclose(fPointer);