Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: "%#s"? Message-ID: <1043@cresswell.quintus.UUCP> Date: 1 Jun 88 06:40:55 GMT References: <1988May28.222450.2680@utzoo.uucp> <4311@haddock.ISC.COM> Organization: Quintus Computer Systems, Mountain View, CA Lines: 31 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. > > > >In the mean-time, why not post sources for a > > spr_str(char *buffer, int width, int places, char *source) > > Since the result is probably going to be handed to printf anyway, I'd get rid > of the width/places arguments and let printf handle them. This keeps the > function simpler. It also makes it very little use. Forget the width argument, which is admittedly not so important. The important one is the .places argument, which serves to terminate the string. If I want to print the first 20 characters of an array which might not have any NULs nearby, I can do printf("%.20s", buffer); or printf("%.*s", 20, buffer); I generally use the second form, as then I can have an expression for the amount that I want written. This is especially useful for debugging, when the bug may involve a clobbered NUL. And this is precisely where I would use %#s if it existed. So it is important that a trial implementation of this operation should let me bound the source this way. I think we can describe the proposed effect of %#c quite succinctly: it writes the shortest sequence of isprint() characters such that both '' and "" would be legal C constants for which the '' version would have the same value as its argument, preferring symbolic forms such as \a to octal forms such as \7. The effect of %#s would be the effect of the appropriate sequence of %#c instances. The effect of %#c on arguments like 'abc' would be implementation-defined.