Compiler: gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main () {
char str[80] = "1995/11/10, Hot Six, Seoul";
char yyyymmdd[11];
const char split[2] = "/";
char *token;
int year, month, day;
memcpy(yyyymmdd, str, 10);
printf("%s\n", yyyymmdd);
token = strtok(yyyymmdd, split);
year = atoi(token);
printf("%d\n", year);
token = strtok(NULL, split);
month = atoi(token);
printf("%d\n", month);
token = strtok(NULL, split);
day = atoi(token);
printf("%d\n", day);
return 0;
}
Results:
1995/11/10
1995
11
10
© 2024 OneMinuteCode. All rights reserved.