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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -