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

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -