CCL Home Page
Up Directory CCL squish_blanks
#include "utility.h"

char *squish_blanks(string)
/*============================================================================*/
/* PURPOSE: SQUISH MULTIPLE CONSECUTIVE BLANKS TO A SINGLE BLANK, AND REMOVE
/*	ALL LEADING AND TRAILING BLANKS FROM THE SPECIFIED STRING.
/* INPUTS:
/*	STRING		STRING WITH EXCESSIVE BLANKS.
/* OUTPUTS:
/*	STRING		MODIFIED STRING, BLANKS COMPRESSED OUT.
/*	RETURN VALUE	POINTER TO MODIFIED STRING.
/* WRITTEN: M.V.GRIESHABER
/* LAST MODIFICATION: 11 JUNE 1991 MVG
*/
   char string[];	/* ORIGINAL STRING (MODIFIED). */
   {
   char *work_string;	/* WORKING COPY OF STRING. */
   char *strtok_ptr;	/* POINTER FOR STRTOK. */
   char *new_string;	/* NEW VERSION OF STRING. */
   char *word;		/* WORD IN STRING. */

   strtok_ptr=string;
   new_string=strdup(string);
   *new_string='\0';

   /* EXTRACT EACH WORD FROM THE STRING AND ADD TO NEW STRING. */
   while ((word=strtok(strtok_ptr," "))!=NULL)
      {
      strcat(new_string,word);
      strcat(new_string," ");
      strtok_ptr=NULL;
      }

   /* ZAP LAST TRAILING BLANK PUT ON IN LOOP. */
   new_string[strlen(new_string)-1]='\0';

   strcpy(string,new_string);
   free(new_string);
   return(string);
   }
Modified: Fri Feb 11 17:00:00 1994 GMT
Page accessed 4799 times since Sat Apr 17 21:59:01 1999 GMT