#include #include #include #include #include #include #include #include int main() { struct stat st = {0}; if (stat("my_journal", &st) == -1){ mkdir("my_journal", 0700); } char command[100], command_2[100], command_3[100], month[20], day[20], year[20], the_date_file[100]; char year_dir[100] = "my_journal/"; FILE * date_file; date_file = fopen("date_file.txt", "w"); time_t tm; time(&tm); fprintf(date_file, "%s", ctime(&tm)); fclose(date_file); date_file = fopen("date_file.txt", "r"); fscanf(date_file, "%s", month); fscanf(date_file, "%s", month); fscanf(date_file, "%s", day); fscanf(date_file, "%s", year); fscanf(date_file, "%s", year); fclose(date_file); //stupid way to change the month to a number if (strcmp(month, "Jan") == 0) strcpy(month, "01"); if (strcmp(month, "Feb") == 0) strcpy(month, "02"); if (strcmp(month, "Mar") == 0) strcpy(month, "03"); if (strcmp(month, "Apr") == 0) strcpy(month, "04"); if (strcmp(month, "May") == 0) strcpy(month, "05"); if (strcmp(month, "Jun") == 0) strcpy(month, "06"); if (strcmp(month, "Jul") == 0) strcpy(month, "07"); if (strcmp(month, "Aug") == 0) strcpy(month, "08"); if (strcmp(month, "Sep") == 0) strcpy(month, "09"); if (strcmp(month, "Oct") == 0) strcpy(month, "10"); if (strcmp(month, "Nov") == 0) strcpy(month, "11"); if (strcmp(month, "Dec") == 0) strcpy(month, "12"); strcpy(the_date_file, "my_journal/"); strcat(year_dir, year); //Check if year directory exists. If not, create it. if (stat(year_dir, &st) == -1){ mkdir(year_dir, 0700); } strcat(the_date_file, year); strcat(the_date_file, "/"); if (month[1] == '\0') strcat(the_date_file, "0"); strcat(the_date_file, month); strcat(the_date_file, "_"); if (day[1] == '\0') strcat(the_date_file, "0"); strcat(the_date_file, day); strcat(the_date_file, "_"); strcat(the_date_file, year); strcat(the_date_file, ".txt"); strcpy(command, "vim "); strcat(command, the_date_file); strcpy(command_2, "touch "); strcat(command_2, the_date_file); system(command_2); strcpy(command_3, "head -c 16 date_file.txt >> "); strcat(command_3, the_date_file); system(command_3); system(command); return 0; }