I have been searching for hours and hours now and cannot figure out why this is not working. I want to create a file in C, in a directory I created, but the file is not being created. Here is the relevant code pertaining to making the directory and creating the file.
#include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> #include<stdio.h> #include<unistd.h> #include<stdlib.h> #include<string.h> #include<time.h> #include<assert.h> char d1[50] = "myname.rooms."; char str[50]; char filename[50]; int d2 = getpid(); int dir; const char *rooms[10] = {"Lillard", "Matthews", "Batum", "Aldridge", "Lopez", "Mccollum", "Leonard", "Blake", "Gee", "Freeland"}; int z; sprintf(str, "%i", d2); strcat(d1, str); dir = mkdir(d1, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); snprintf(filename, 50, "/%s/%s.txt", d1, rooms[0]); z = strlen(filename); for(i=0; i<z; i++) { str[i] = filename[i]; } FILE *f; f = fopen("str", "w+"); fprintf(f, "ROOM NAME: %s\n", (rooms[0])); fclose(f); Making the directory works, there is just no file created in that directory or anywhere else. I want to loop through and create files for each of those rooms, but I just wanted to get it to function with 1 first. I printed out the str string and it came out as /myname.rooms.22222/Lillard.txt where myname.rooms.22222 is the directory and Lillard.txt should be the file name. I am stuck right now, please help.