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

  

相关文章:

  • 2021-12-04
  • 2022-12-23
  • 2022-02-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-13
  • 2022-01-06
猜你喜欢
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2022-02-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案