1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #include <string.h> 7 8 9 char* 10 strsep(char** string, const char* delimiters) 11 { 12 if (*string == NULL) 13 return NULL; 14 15 // find the end of the token 16 char* token = *string; 17 char* end = token; 18 while (*end != '\0' && strchr(delimiters, *end) == NULL) 19 end++; 20 21 // terminate the token and update the string pointer 22 if (*end != '\0') { 23 *end = '\0'; 24 *string = end + 1; 25 } else 26 *string = NULL; 27 28 return token; 29 } 30