我在使用该strtok()
功能时遇到问题。我喂这个日期01/01/2000
; 我的预期输出是:1、1、2000;但是我只是得到 1、1、1。这是为什么呢?
#include <stdio.h>
#include <stdlib.h>
#include "date.h"
#include <string.h>
struct date{
int day;
int month;
int year;
};
Date *date_create(char *datestr){
printf("inside date_create");
char delim[] = "/";
Date* pointerToDateStructure = malloc(sizeof(Date));
printf("%s",datestr);
char string[10];
*strcpy(string, datestr);
pointerToDateStructure->day = atoi(strtok( string, delim));
pointerToDateStructure->month = atoi(strtok( string, delim));
pointerToDateStructure->year = atoi(strtok( string, delim));
printf("%d", pointerToDateStructure->day);
printf("%d", pointerToDateStructure->month);
printf("%d", pointerToDateStructure->year);
return pointerToDateStructure;
}