I could be doing this completely the wrong way, but considering this will be for personal use, having it not be that efficient is okay.
When ran as ./todo -r
, it works.
When ran as ./todo -a
, it works.
When ran as ./todo
, it gives me segmentation fault (core dumped)
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char *argv[]) {
if(argc < 1) {
printf("Not enough variables.");
}
if(strcmp("-r",argv[1])==0) {
printf("\n");
system("cat .todo");
printf("\n");
}
if(strcmp("-a",argv[1])==0) {
char str[BUFSIZ];
FILE *f;
f = fopen(".todo","a");
printf("\n\nTODO list\n\n");
for(;;) {
printf("~ ");
fgets(str,256,stdin);
if(strcmp(str,"\n")==0) {
fclose(f);
printf("\n");
break;
}
fprintf(f,str);
}
return 0;
}
}