home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
xbase
/
library
/
clipper
/
rettig
/
source
/
rjust.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-21
|
1KB
|
57 lines
/*********
*
* RJUST.C
*
* by Tom Rettig
*
* Placed in the public domain by Tom Rettig Associates, 10/22/1990.
*
* Syntax: RJUST( <expC> )
* Return: <expC> with trailing spaces moved to left end.
* Return string is same length as <expC>.
*********/
#include "trlib.h"
TRTYPE rjust()
{
char *instr, *ret;
int i, j, pos, len;
static char funcname[] = { "rjust" };
if ( PCOUNT==1 && ISCHAR(1) )
{
instr = _parc(1);
len = _tr_strlen(instr);
ret = _tr_allocmem( (unsigned)(len+1));
if ( ret )
{
if ( instr[len-1]==SPACEC )
{
for ( j=len-1; instr[j]==SPACEC; j-- )
;
pos = ++j; /* right: first char past spaces */
for ( i=0; instr[j]==SPACEC; i++, j++ )
ret[i] = instr[j];
/* fill return buffer with chars */
for ( j=0; j<pos; i++, j++ )
ret[i] = instr[j];
ret[i] = NULLC;
_retc( ret );
}
else /* return unchanged if no trailing spaces */
_retc( instr );
_tr_freemem( ret,(unsigned)(len+1));
}
else /* return unchanged if no memory */
_retc( instr );
}
else
_retc( _tr_errmsgs(funcname,E_SYNTAX) );
}