1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| #include <stdio.h> #include <stdlib.h> #include <time.h> #include <unistd.h>
char filename[100] = {0};
const char *dir = 0;
char real_file_name[100] = {0};
char *getTime() { struct tm *timeinfo; time_t rawtime; char *buffer = malloc(sizeof(char) * 80);
time(&rawtime); timeinfo = localtime(&rawtime);
strftime(buffer, 80, "%Y-%m-%d", timeinfo); return buffer; }
FILE *creatFile() { char *currentTime = getTime(); char *lastName = "_log.txt"; dir = "/Users/******/Daily_Life_Log/";
snprintf(real_file_name, 100, "%s%s", currentTime, lastName);
snprintf(filename, sizeof(filename), "%s%s%s", dir, currentTime, lastName); FILE *file = fopen(filename, "a"); if (file != NULL) { printf("文件已创建成功!\n"); } else { printf("无法创建文件!\n"); } return file; }
int main(int argc, char *argv[]) { if (argc < 2) { printf("请输入日志!\n"); return -1; }
FILE *file = creatFile(); for (int i = 1; i < argc; i++) { fprintf(file, "%s", argv[i]); fprintf(file, "%s", " "); } fprintf(file, "%s", "\n"); fclose(file);
if (chdir(dir) == 0) { printf("目录切换成功!\n"); } else { perror("chdir"); }
char git_add[100] = {0}; snprintf(git_add, sizeof(git_add), "%s%s", "git add ", real_file_name); system(git_add);
char *command0 = "git commit -m \""; char *tag1 = "\""; char command1[100] = {0}; snprintf(command1, sizeof(command1), "%s%s%s", command0, real_file_name, tag1); system(command1);
system("git push"); return 0; }
|