Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

left trim program

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am using Borland Compiler 5.5.1. Does anyone have an idea on how to write a routine that will allow me to 'left trim' a string. Please correct the following program.



#include <string.h>
#include &quot;EditUtil.h&quot;


// Routine: leftTrim ()
// Programmer:
// Purpose: This routine trims in place from a c-string, leading tabs and spaces.
// Parameters: pString - type char * : The string to be left trimmed in place.
// Returns: Nothing


void leftTrim (char * pString )

{

int length = strlen ( pString ) ;
if ( length == 0 ) return ;
// char ch ;
int i, j, k;
bool found;

// Starting at the beginning of the string, move towards the end until you find a non space and non tab
// character

found = false;
for ( i = 0 ; i < length ; i ++ )
{
// ch = pString [ i ];
// if ( ch ! = TAB && ch ! = SPACE )
{
j = i;
found = true;
break;
}
} //
//
if ( found == true ) {

for ( k = 0 ; k < length - j ; k + 1 );
}
pString [ k ] = pString [ j + k ];
{
pString [ k ] = NULL_TERMINATOR;

}

pString [ 0 ] = NULL_TERMINATOR;

{
}


}



 
Take a look at ctype. This is a part of the standard library for C/C++. It includes functions like isspace, isdigit, etc. For example,

if (!isspace(ch) || !iscntrl(ch))
{
// Looks to see if character ch is a space or control character
[tab].
[tab].
[tab].
}




James P. Cottingham

All opinions are mine alone and do not necessarily reflect those of my employer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top