placing output of printf in memory: formatting strings

David Tanguay datangua at watmath.waterloo.edu
Fri Jun 21 09:05:50 AEST 1991


In article <1991Jun19.233752.24019 at athena.mit.edu> scs at 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 at watmath.waterloo.edu        Thinkage, Ltd.



More information about the Comp.lang.c mailing list