- typedef struct string_buf_s string_buf_t;
- struct string_buf_s{
- char buffer[20];
- int buf_len;
- };
- int string_splite(char *str, char *delims, string_buf_t *strbuf)
- {
- int count = 0;
- if (str == NULL || delims == NULL)
- return -1;
- char *result = NULL;
- result = strtok(str, delims);
- while (result != NULL)
- {
- strcpy(strbuf[count].buffer, result);
- strbuf[count].buf_len = strlen(result);
- result = strtok(NULL, delims);
- count++;
- }
- return count;
- }
- //该片段来自于http://www.codesnippet.cn/detail/0607201513011.html
来源: http://www.codesnippet.cn/detail/0607201513011.html