I have a text file myfile.txt, and at the very bottom of it I have.
Thanks for reading, goodnight.\n\n
How would I remove those 2 newline characters? I can open the file for writing, but can't figure out how to remove just those 2 from the very end.
I have a text file myfile.txt, and at the very bottom of it I have.
Thanks for reading, goodnight.\n\n
How would I remove those 2 newline characters? I can open the file for writing, but can't figure out how to remove just those 2 from the very end.
Just truncate the file by 2 characters:
int fd = open("file.txt", O_WRONLY);
fseek(fd, 0L, SEEK_END);
int sz = ftell(fp);
close(fd);
truncate("file.txt", sz - 2);
You are supposed to leave at lease one new line character at the end of a text file, but it isn't a requirement: