0
string input = 1999-12-05
int year=1999
int month=12
int day=05

I want to split input to new three variable.Thank you.

1 Answers1

0

You can use sscanf:

char* input = "1999-12-05";
int year;
int month;
int day;
sscanf(input, "%d-%d-%d", &year, &month, &day);
printf("year: %d, month: %d, day: %d\n", year, month, day);

demo

Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • 1
    It's best to check `sscanf`'s return value. If it's not 3 in this case, something has gone wrong, and not all three values were converted. – Steve Summit Sep 13 '21 at 15:02