Newsgroups: comp.lang.c
Path: utzoo!utgpu!watserv1!watmath!datangua
From: datangua@watmath.waterloo.edu (David Tanguay)
Subject: Re: placing output of printf in memory: formatting strings
Message-ID: <1991Jun20.230550.6528@watmath.waterloo.edu>
Keywords: string, format, printf
Organization: University of Waterloo
References: <965@baby.and.nl> <1729@seq.uncwil.edu> <1991Jun19.233752.24019@athena.mit.edu>
Date: Thu, 20 Jun 1991 23:05:50 GMT
Lines: 23

In article <1991Jun19.233752.24019@athena.mit.edu> scs@adam.mit.edu writes:
>	extern FILE *stropen();
>	char buf[80];
>	FILE *sfp = stropen(buf, "w");
>	fprintf(sfp, "Hello, ");
>	fputs("world!", sfp);
>	putc('\n', sfp);

Our compiler implements this functionality via
	sfp = fopen(buf, "ws"); /* note the "s" for string */
There are corrsponding "rs", "as", "wb", etc. modes for reading strings
or raw bytes from memory (the "b"). There should be a way of specifying
the maximum string length: fopen(buf, "ws:80") or stropen(buf, "w", 80).

It's in our run-time because the C run-time is really just an interface
to the B run-time (although we have since propagated the functionality).

>More useful
>would be a way to arrange for the characters "written" to a FILE *
>to be neither written to a "file" nor accumulated in a string,
>but rather passed to a user-defined output function.
-- 
David Tanguay        datanguay@watmath.waterloo.edu        Thinkage, Ltd.
