2019-12-09 13:37发布
菜包 发表于 2019-11-25 16:49 这个函数不复杂啊,你不想用库也可以照着源码弄个函数用
fbwcpu 发表于 2019-11-25 18:06 在STM32F10X上可以用? 比较费内存吧?
最多设置5个标签!
- /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
- #include <string.h>
- char* strtok(char *s, const char *delim)
- {
- const char *spanp;
- int c, sc;
- char *tok;
- static char *last;
- if (s == NULL && (s = last) == NULL)
- return (NULL);
- /*
- * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
- * 跳过字符串首部的分隔符
- */
- cont:
- c = *s++;
- for (spanp = delim; (sc = *spanp++) != 0;) {
- if (c == sc)
- goto cont;
- }
-
- /*
- *分割符后面没有字符串了
- */
- if (c == 0) { /* no non-delimiter characters */
- last = NULL;
- return (NULL);
- }
- tok = s - 1; /*分割符后面还有字符串,将tok指向字符串首部(不包括分隔符)*/
- /*
- * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
- * Note that delim must have one NUL; we stop if we see that, too.
- * 循环字符串中的字符,直到找到分隔符或者结束符,并替换成结束符
- */
- for (;;) {
- c = *s++;
- spanp = delim;
- /*
- *判断字符串中的某字符是否是分割符中的字符
- *如果是,将分隔符替换成结束符并返回tok;
- *如果不是,继续判断下一个字符
- */
- do {
- if ((sc = *spanp++) == c) {
- if (c == 0)
- s = NULL;
- else
- s[-1] = 0;
- last = s;
- return (tok);
- }
- } while (sc != 0);
- }
- /* NOTREACHED */
- }
复制代码在STM32F10X上可以用? 比较费内存吧?
源码都贴出来了,就那么几个变量,你觉得会用多少内存
一周热门 更多>