C语言切割字符串


  /******************************************************************************

  *

  *    FUNCTION:    Split

  *

  *    PURPOSE:    Split a delimited line into components

  *

  ******************************************************************************/

  int Split( char * line, char delimiter, char * items[] )

  {

  int        cnt = 0;

  for (;;)  {

  // Add prefix to list of components

  items[cnt++] = line;

  // Check for more components

  line = strchr( line, delimiter );

  if ( line == NULL )

  return cnt;

  // Terminate previous component and move to next

  *line++ = '\\0';

  }

  }

相关内容