Search code examples
cdatestdin

date format dd.mm.yyyy in C


I want to know if there is a way to read date from console in format dd.mm.yyyy in C. I have a structure with information for the date. I tried with another structure just for the date with day, month and year in it:

typedef struct
{
    int day;
    int month;
    int year;
} Date;

but the dots are a problem. Any idea?


Solution

  • Try:

      Date d;
      if (scanf("%d.%d.%d", &d.day, &d.month, &d.year) != 3)
        error();