On Thu, Oct 07, 2010 at 08:05:20PM +0200, Erik Faye-Lund wrote: > >> I don't know which one would be most portable, but if fwrite is the > >> problem, then > >> > >> Â printf("%*s%c", buf.buf, buf.len, info->hdr_termination); > >> > >> should do the trick. > > > > It does work, but you have to cast the buf.len size_t to an int. > > > I'm not sure how portable it is, though. This is what K&R has to say > on the matter: "characters from the string are printed until a Â\0Â is > reached or until the number of characters indicated by the precision > have been printed". To me it's not clear if that means that either > cases can terminate the printing when the precision has been > specified. I take it back. It doesn't actually work (I thought I had done this just recently, but clearly not). Try: #include <stdio.h> int main() { char buf[] = "123456789"; buf[2] = '\0'; printf("%.*s\n", 5, buf); return 0; } It prints just "12" for me. -Peff -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html