What is wrong with this program?

Chris Torek chris at umcp-cs.UUCP
Sun Aug 18 09:03:18 AEST 1985


>... you are forgetting that the format "%.8s" will cause printf to
>print up to a null or 8 chars max.  Unfortunately this style of
>printf can not be used with sizeof for compile time format changes
>without run time code support.

Well, you can always use:

	printf("%.*s", sizeof (utmp.ut_name), utmp.ut_name);

or if you want exactly sizeof (utmp.ut_name) characters:

	#define NMAX (sizeof (utmp.ut_name))

	printf("%-*.*s", NMAX, NMAX, utmp.ut_name);

(The "-" gives "left adjustment"---blank filling at the right.)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at maryland



More information about the Comp.lang.c mailing list