c strsep函数demo
在string.h中,分割字符串
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char date[50] = "2019-10-1"; char delim[2] = "-"; char *s = strdup(date); char *token; for (token = strsep(&s, delim); token != NULL;token = strsep(&s, delim)) { printf("s:%s\n", s); printf("toke:%s\n", token); } free(s); return 0; }
Please call me JiangYouDang!