日期格式dd.mm.yyyy在C [英] date format dd.mm.yyyy in C

查看:143
本文介绍了日期格式dd.mm.yyyy在C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方式从C中以dd.mm.yyyy格式从控制台读取日期。我有一个包含日期信息的结构。我尝试使用另一种结构,只是在日期,月份和年份的日期:

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?

推荐答案

尝试:

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

这篇关于日期格式dd.mm.yyyy在C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆