How to truncate a file in C?

If you want to preserve the previous contents of the file up to some length (a length bigger than zero, which other answers provide), then POSIX provides the truncate() and ftruncate() functions for the job. #include <unistd.h> int ftruncate(int fildes, off_t length); int truncate(const char *path, off_t length); The name indicates the primary purpose – … Read more

Ellipsis in the middle of a text (Mac style)

In the HTML, put the full value in a custom data-* attribute like <span data-original=”your string here”></span> Then assign load and resize event listeners to a JavaScript function which will read the original data attribute and place it in the innerHTML of your span tag. Here is an example of the ellipsis function: function start_and_end(str) … Read more

Truncate a string to first n characters of a string and add three dots if any characters are removed

//The simple version for 10 Characters from the beginning of the string $string = substr($string,0,10).’…’; Update: Based on suggestion for checking length (and also ensuring similar lengths on trimmed and untrimmed strings): $string = (strlen($string) > 13) ? substr($string,0,10).’…’ : $string; So you will get a string of max 13 characters; either 13 (or less) … Read more