Facebook
From Unreliable Macaque, 2 Months ago, written in Plain Text.
This paste is a reply to Untitled from Mustard Owl - view diff
Embed
Download Paste or View Raw
Hits: 47
  1. int main(int argc, char *argv[])
  2. {
  3.  if(argc < 3) die("USAGE: ex17 <dbfile> <action> [action params]");
  4.  char *filename = argv[1];
  5.  char action = argv[2][0];
  6.  struct Connection *conn = Database_open(filename, action);
  7.  int id = 0;
  8.  if(argc > 3) id = atoi(argv[3]);
  9.  if(id >= MAX_ROWS) die("There's not that many records.");
  10.  switch(action) {
  11.  case 'c':
  12.  Database_create(conn);
  13.  Database_write(conn);
  14.  break;
  15.  case 'g':
  16.  if(argc != 4) die("Need an id to get");
  17.  Database_get(conn, id);
  18.  break;
  19.  case 's':
  20.  if(argc != 6) die("Need id, name, email to set");
  21.  Database_set(conn, id, argv[4], argv[5]);
  22.  Database_write(conn);
  23.  break;
  24.  case 'd':
  25.  if(argc != 4) die("Need id to delete");
  26.  Database_delete(conn, id);
  27.  Database_write(conn);
  28.  break;
  29.  case 'l':
  30.  Database_list(conn);
  31.  break;
  32.  default:
  33.  die("Invalid action, only: c=create, g=get, s=set, d=del, l=list");
  34.  }
  35.  Database_close(conn);
  36.  return 0;
  37. }
  38.  

Replies to Re: Untitled rss

Title Name Language When
Re: Re: Untitled Scribby Owl text 2 Months ago.