C언어 문자열 특정 문자or숫자 갖고오는법
조회수 5455회
1 답변
-
컴파일러: 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,핫식스,서울"; 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; } 결과: 1995/11/10 1995 11 10
댓글 입력