aboutsummaryrefslogtreecommitdiff
path: root/tests/test11.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test11.c')
-rw-r--r--tests/test11.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/test11.c b/tests/test11.c
new file mode 100644
index 000000000..1460141f7
--- /dev/null
+++ b/tests/test11.c
@@ -0,0 +1,57 @@
+#include "uthash.h"
+#include <stdlib.h> /* malloc */
+#include <errno.h> /* perror */
+#include <stdio.h> /* printf */
+
+#define BUFLEN 20
+
+#if 0
+/* Print a message if the hash's no-expand flag is set. */
+#undef uthash_noexpand_fyi
+#undef uthash_expand_fyi
+#define uthash_noexpand_fyi(tbl) printf("noexpand set\n");
+#define uthash_expand_fyi(tbl) printf("hash expanded\n");
+#endif
+
+typedef struct name_rec {
+ char boy_name[BUFLEN];
+ UT_hash_handle hh;
+} name_rec;
+
+static int namecmp(void *_a, void *_b)
+{
+ name_rec *a = (name_rec*)_a;
+ name_rec *b = (name_rec*)_b;
+ return strcmp(a->boy_name,b->boy_name);
+}
+
+int main()
+{
+ name_rec *name, *names=NULL;
+ char linebuf[BUFLEN];
+ FILE *file;
+
+ file = fopen( "test11.dat", "r" );
+ if (file == NULL) {
+ perror("can't open: ");
+ exit(-1);
+ }
+
+ while (fgets(linebuf,BUFLEN,file) != NULL) {
+ name = (name_rec*)malloc(sizeof(name_rec));
+ if (name == NULL) {
+ exit(-1);
+ }
+ strcpy(name->boy_name, linebuf);
+ HASH_ADD_STR(names,boy_name,name);
+ }
+
+ fclose(file);
+ HASH_SORT(names,namecmp);
+ for(name=names; name!=NULL; name=(name_rec*)(name->hh.next)) {
+ printf("%s",name->boy_name);
+ }
+
+ return 0;
+}
+