Anonymous user
Simple database: Difference between revisions
→{{header|C}}: As I wrote, previous version does not compile. Now all works fine.
m (→{{header|C}}: Fixed incomplete edit 155789 from 20 April 2013) |
(→{{header|C}}: As I wrote, previous version does not compile. Now all works fine.) |
||
Line 64:
sort_by(last_name);
sort_by(title);
static
/* main */
int main (int argc, char **argv) {
Line 76:
TRY (f=fopen(DB,"a+"));
if (argc<2) {
usage: printf ("Usage: %s [commands]\n"
"-c Create new entry.\n"
"-p Print the latest entry.\n"
"-t Print all entries sorted by title.\n"
"-d Print all entries sorted by date.\n"
"-a Print all entries sorted by author.\n",argv[0]);
fclose (f);
Line 112:
printf ("-d Print all entries sorted by date.\n");
dblist = dao (READ,f,&db,NULL);
dblist = dao (SORT,f,dblist,(int (*)(const void *,const void *)) by_date);
dao (PRINT,f,dblist,NULL);
dao (DESTROY,f,dblist,NULL);
Line 191:
qsort (pdb,i,sizeof in_db,sortby);
pdb[i-1]->next=NULL;
for (i=i-1;i;i--) {
pdb[i-1]->next=pdb[i];
}
Line 221:
}
/* sort by date callback for qsort */
static int by_date (
return -1;
}</lang>
|