c - Clear 2 newline characters from the end of a file -
i have text file myfile.txt, , @ bottom of have.
thanks reading, goodnight.\n\n
how remove 2 newline characters? can open file writing, can't figure out how remove 2 end.
just truncate file 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 supposed leave @ lease 1 new line character @ end of text file, isn't requirement:
Comments
Post a Comment