#include #include "debug.h" #include "suppress_spaces.h" int suppress_spaces( char *buffer ) { char *tmpbuf; int length, cnt, offset, seen_space; /* Suppresses runs of spaces, so that they become 1 space. Good for indexing */ length = strlen( buffer ); tmpbuf = (char *)malloc( length + 1 ); bzero( tmpbuf, length + 1 ); offset = 0; seen_space = 0; for( cnt = 0; cnt < length; cnt++ ) { if( buffer[ cnt ] == ' ' ) { /* Only add if we haven't yet seen space */ if( ! seen_space ) { tmpbuf[ offset++ ] = buffer[ cnt ]; seen_space = 1; } }else { seen_space = 0; tmpbuf[ offset++ ] = buffer[ cnt ]; } } /* Put it back in the main buffer now */ strcpy( buffer, tmpbuf ); free( tmpbuf ); return( 0 ); }