Re: ^Ms, easier solution

From: The Awakening (awake@texas.net)
Date: 11/25/95


Heya folks, no need to use strtok as someone posted.  You all need to 
practice playing with strings (=.  Here's a faster way to do it.

/* strips ^M 's from line */
char *cleanup(char *dest, const char *src)
{
  int i = 0, length = strlen(src);

  for (; *src && (i < length); i++, src++)
     if (*src != '\r')
       *(dest++) = *src;

  // terminate it properly
  *dest = '\0';

  return dest;
}

Just put this wherever you like (utils.cc most likely), add an
extern char *cleanup(char *dest, const char *src) to any file you want
to use it in, and call it when you need it like this:

printf(buf, "%s", cleanup(buf1, messy_string_here);

Have fun.

Chris
(awake@texas.net)
(http://www.texas.net/~awake)
(awake.gstand.com 4000)

"Try not!  Do or do not!  There is no try!"  --Yoda, Jedi Master



This archive was generated by hypermail 2b30 : 12/07/00 PST