#Making a ToDo List but....
33 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
as soon as I delete the code
what?
How are you writing to the file?
How do you know the data is there while the program is running?
Or did you mean that the file was previously containing text, but after the program execution it completely erased all content or did it really remove the file?
That's probably because you opened the file in w mode
Yeah, this line here:
FILE *file = fopen("todolist.csv", "w");
```opens the `todolist.csv` file and truncates it (i.e. clears it)
!man fopen
fopen, fdopen, freopen - stream open functions
#include <stdio.h>
FILE *fopen(const char *restrict pathname, const char *restrict mode);
FILE *fdopen(int fd, const char *mode);
FILE *freopen(const char *restrict pathname, const char *restrict mode,
FILE *restrict stream);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
fdopen():
_POSIX_C_SOURCE
w Truncate file to zero length or create text file for
writing. The stream is positioned at the beginning of the
file.
a or a+. Whatever fits your needs better I guess.
a if you only want to write to it, a+ if you also want to be able to read
i recently learnt file handling so been making a few mistakes
aah cool
a Open for appending (writing at end of file). The file is
created if it does not exist. The stream is positioned at
the end of the file.a+ Open for reading and appending (writing at end of file). The file is created if it does not exist. Output is always appended to the end of the file. POSIX is silent on what the initial read position is when using this mode. For glibc, the initial file position for reading is at the beginning of the file, but for Android/BSD/MacOS, the initial file position for reading is at the end of the file.