I need to change the last character in large text files where the space between the end of the text and the EOF is padded with a handful of NULL characters. The problem is to find out where the text ends and the NULL padding begins.
I could read the file to a huge buffer and then check the length of the text with strlen() and then stet the write position according to the strlen() of the buffer. But, on a large file this is time consuming and costly in resources.
Is there any way of reading the file backwards, starting from the EOF (fseek(fp, 0L, SEEK_END)), one character at a time, until the first non-null character is encountered?