/* * pack_queue.c * * shuhan * * 2010-2-16 15:56:43 */ #include <sys/queue.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { SIMPLEQ_HEAD(MyStruct, Entry) pack_queue; struct Entry { SIMPLEQ_ENTRY(Entry) q; char * itemp; }; SIMPLEQ_INIT(&pack_queue); struct Entry * line1 = malloc(sizeof(struct Entry)); line1->itemp = strdup("string one/n"); SIMPLEQ_INSERT_TAIL(&pack_queue, line1, q); line1 = malloc(sizeof(struct Entry)); line1->itemp = strdup("string two/n"); SIMPLEQ_INSERT_TAIL(&pack_queue, line1, q); line1 = malloc(sizeof(struct Entry)); line1->itemp = strdup("string three/n"); SIMPLEQ_INSERT_TAIL(&pack_queue, line1, q); line1 = malloc(sizeof(struct Entry)); line1->itemp = strdup("string four/n"); SIMPLEQ_INSERT_TAIL(&pack_queue, line1, q); struct Entry * innerp = NULL; SIMPLEQ_FOREACH(innerp, &pack_queue, q) { printf("%s", innerp->itemp); free(innerp->itemp); innerp->itemp = NULL; } return 0; }