home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_10_11
/
1011119b
< prev
next >
Wrap
Text File
|
1992-09-14
|
745b
|
34 lines
/* align.c: Align a string within a background */
#include <string.h>
#define LEFT (-1)
#define CENTER 0
#define RIGHT 1
#define min(x,y) ((x) <= (y) ? (x) : (y))
char *align(char *buf,int width,char fill,int justify,char *data)
{
char *p;
/* Truncate, if necessary */
int dlen = min(width,strlen(data));
/* Populate with fill character */
memset(buf,fill,width);
buf[width] = '\0';
/* Calculate starting point */
if (justify == LEFT)
p = buf;
else if (justify == CENTER)
p = buf + (width-dlen)/2;
else
p = buf + width-dlen;
/* Insert the data there */
memcpy(p,data,dlen);
return buf;
}