commit 3387f9ead085a09c7fe1dd28d9f2e56c3db69c75
parent 4159537fc9ae6eeef339fff661e025b6b05a467e
Author: brookjeynes <me@brookjeynes.dev>
Date: Wed, 10 Jun 2026 11:02:34 +0000
feat: write title to file
Diffstat:
| M | main.c | | | 26 | ++++++++++++++++++++++---- |
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/main.c b/main.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/stat.h>
struct options {
char *title;
@@ -71,7 +72,6 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "err: priority must be between [A-Z]\n");
exit(1);
}
- printf("(%c)\n", cli_args.priority);
}
int title_len = strlen(cli_args.title);
@@ -85,12 +85,30 @@ int main(int argc, char *argv[]) {
}
strcpy(title_to_file + title_len, ".txt");
- printf("%s\n", cli_args.title);
- printf("%s\n", title_to_file);
+ struct stat buffer;
+ if (stat(title_to_file, &buffer) == 0) {
+ fprintf(stderr, "err: file already exists\n");
+ exit(1);
+ };
+
+ FILE *f = fopen(title_to_file, "w");
+ if (f == NULL) {
+ fprintf(stderr, "err: failed to open file\n");
+ exit(1);
+ }
+
+ if (cli_args.priority != '\0') {
+ fprintf(f, "(%c) ", cli_args.priority);
+ }
+
+ fprintf(f, "%s", cli_args.title);
if (cli_args.properties != NULL) {
- printf("%s\n", cli_args.properties);
+ fprintf(f, " %s", cli_args.properties);
}
+ fprintf(f, "\n");
+ fclose(f);
+
return 0;
}