如何检查当前是否设置了警报?

时间:2015-08-03 21:19:29

标签: c

我正在尝试编写一个简单的C应用程序,它接受用户输入并根据它设置alarm()。但是,如果已经设置了警报,我不希望用户覆盖它,所以我需要一种方法来检查是否已设置警报而不覆盖当前警报。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

使用包含struct的标记并在设置闹钟时设置。在设置警报之前,请确保尚未设置标志。确保每次创建新的闹钟,即结构的对象时,将标志值设置为零,表示它未在开始时设置。

typedef struct AlarmClock {
      Time startTime;
      //Any other fields that you want
      int isSet;
}AC;



//Try to set the alarm and returns the status
 boolean setAlarm(AC *ac,Time time) {
    if(ac->isSet) {
        //Alarm is alreadyt set. Return false
        return false;
    }
    ac->startTime = time;
    ac->isSet= 1;
    return true;
 }