C语言切割字符串

2014-11-24 02:45:49 · 作者: · 浏览: 3

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


  *


  * 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';


  }


  }