Path: utzoo!attcan!uunet!husc6!bloom-beacon!mcgill-vision!mouse
From: mouse@mcgill-vision.UUCP (der Mouse)
Newsgroups: comp.lang.c
Subject: Re: "%#s"?
Message-ID: <1156@mcgill-vision.UUCP>
Date: 12 Jun 88 11:15:27 GMT
References:  <1988May28.222450.2680@utzoo.uucp> <4311@haddock.ISC.COM>
Organization: McGill University, Montreal
Lines: 34

In article <4311@haddock.ISC.COM>, karl@haddock.ISC.COM (Karl Heuer) writes:
> In article <1039@cresswell.quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes:
>> In article <19166@watmath.waterloo.edu>, rbutterworth@watmath.waterloo.edu (Ray Butterworth) writes:
>>> Perhaps %#s and %#c can be added in future updates to the language.
>> spr_str(buf, width, 1, &c) can serve for sprintf(buf, "%#*c", width, c).
> Not if c is declared register and/or int (both of which are common
> when dealing with text).  I think this case is sufficiently useful
> and simple that it deserves to be a separate function: char
> *spr_chr(int c); the buffer itself can be static.

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));

With a domain as small as a char, it would even work to

static char *strings[] = { "EOF", "^@", "^A", ...., "\\377" };
/* or whatever strings you want */
/* this example assumes EOF is -1 */

char *spr_chr(int chr)
{
 return(((chr==EOF)||(chr==(int)(unsigned char)chr))?strings[chr+1]:"OOPS");
}

(by the way, is the chr==(int)(unsigned char)chr test a safe way of
testing whether the value is one an unsigned char could take on?)

					der Mouse

			uucp: mouse@mcgill-vision.uucp
			arpa: mouse@larry.mcrcim.mcgill.edu