Path: utzoo!attcan!uunet!vsi!friedl From: friedl@vsi.UUCP (Stephen J. Friedl) Newsgroups: comp.lang.c Subject: Re: "%#s"? Summary: I use circbuf() for this Message-ID: <715@vsi.UUCP> Date: 13 Jun 88 01:55:34 GMT References:<1988May28.222450.2680@utzoo.uucp> <1156@mcgill-vision.UUCP> Organization: V-Systems, Inc. -- Santa Ana, CA Lines: 37 In article <1156@mcgill-vision.UUCP>, mouse@mcgill-vision.UUCP (der Mouse) writes: > > [let's have spr_chr(int c) to return a stringized version of a char] > > If you are going to use a static buffer, folks, please use several of > them, or otherwise arrange that it doesn't lose big if I say > > printf(" in_chr = %s, out_chr = %s\n", > spr_chr(in_chr), spr_chr(out_chr)); For exactly this kind of thing we use a routine circbuf(). It has a large static buffer and returns chunks to you upon request: /*----------------------- circbuf.c ------------------------*/ #define ASIZE 1024 char * circbuf(size) int size; { static char circarray[ASIZE], *nextfree = circarray; if ((nextfree + size) > &circarray[ASIZE]) /* enough room? */ nextfree = circarray; /* recycle */ return((nextfree += size) - size)); } /*----------------------- circbuf.c ------------------------*/ This is a handy malloc-like function that you don't have to free up. It strikes me as a little dangerous that you have to pay attention to the lifetime of one of these strings (it will get overwritten later), but we've not seen any problems with it. -- Steve Friedl V-Systems, Inc. (714) 545-6442 3B2-kind-of-guy friedl@vsi.com {backbones}!vsi.com!friedl attmail!vsi!friedl Nancy Reagan on ptr args with a prototype in scope: "Just say NULL"