atexit.c

来自「palm的pocketc」· C语言 代码 · 共 46 行

C
46
字号
// atexit
// This is an example of using the atexit() function to save the applet
// state when the user switches apps
int x1, x2, y1, y2;

savestuff() {
  if (dbcreate("atexitSaveDB")) {
    dbwrite(x1);
    dbwrite(y1);
    dbwrite(x2);
    dbwrite(y2);
  }
}

loadstuff() {
  if (dbopen("atexitSaveDB")) {
    x1 = dbread('i');
    y1 = dbread('i');
    x2 = dbread('i');
    y2 = dbread('i');
  }
}

main() {
  int e;

  loadstuff();
  atexit(savestuff); // pass the pointer to savestuff()
  graph_on();
  title("Drag the pen");
  line(1, x1, y1, x2, y2);
  
  do {
    e = event(1);
    if (e == 2) {
      x1 = penx();
      y1 = peny();
    }
    if (e == 3) {
      x2 = penx();
      y2 = peny();
      clearg();
      line(1, x1, y1, x2, y2);
    }
  } while (1);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?