From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: Centering printf text on a 80 column screen Date: Tue, 08 Apr 1997 05:41:41 -0700 Organization: Two pounds of chaos and a pinch of salt Message-ID: <334A3D05.230D@cs.com> References: <334aed58 DOT 5263168 AT news DOT mindspring DOT com> Reply-To: fighteer AT cs DOT com NNTP-Posting-Host: ppp205.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 44 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp dabrownz AT mindspring DOT com wrote: > > How do you center printf text on a DOS screen? I can't find anyway to > do this other than using tabs and spaces (very annoying). What is the > 'correct' way to do it? Do I have to use 'cprintf' or some other > keyword or include another library? I'd would really appriciate any > help, Thanks. Here's probably the easiest way to do what you describe: char line[256]; sprintf( line, format-string, args ); printf( "%*s\n", screen_width / 2 + strlen( line ) / 2, line ); You could put this in a function that could be called just like the regular printf() like so: #include #include #define SCREEN_WIDTH 80 int printf_centered( const char *fmt, ... ) { char line[256]; va_list v; va_start( v, fmt ); vsprintf( line, fmt, v ); va_end( v ); return printf( "%*s\n", (int) ( SCREEN_WIDTH / 2 + strlen( line ) / 2 ), line ); } If I had some more time I could probably come up with a more elegant way, but this should be fine for most purposes. -- --------------------------------------------------------------------- | John M. Aldrich, aka Fighteer I | mailto:fighteer AT cs DOT com | | God's final message to His Creation: | http://www.cs.com/fighteer | | "We apologize for the inconvenience."| Fight against proprietary | | - Douglas Adams | software - support the FSF!| ---------------------------------------------------------------------