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;
}

  

posted on 2020-03-04 00:23  luckygxf  阅读(681)  评论(0编辑  收藏  举报

导航