在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 ", s); printf("toke:%s ", token); } free(s); return 0; }