home *** CD-ROM | disk | FTP | other *** search
/ C/C++ User's Journal & Wi…eveloper's Journal Tools / C-C__Users_Journal_and_Windows_Developers_Journal_Tools_1997.iso / windbase / windbase.exe / MEMSLC.3 / DQUEUE.C < prev    next >
C/C++ Source or Header  |  1996-07-11  |  4KB  |  102 lines

  1. /*****************************************************************************\
  2. **                                                                           **
  3. **  WW     WW IIIIIIII NNN   NN DDDDDDD  BBBBBBB     AA     SSSSSS EEEEEEEE  **
  4. **  WW  W  WW    II    NNNN  NN DD    DD BB    BB  AA  AA  SS      EE        **
  5. **  WW  W  WW    II    NN NN NN DD    DD BBBBBBB  AAAAAAAA  SSSSSS EEEEEE    **
  6. **   WW W WW     II    NN  NNNN DD    DD BB    BB AA    AA      SS EE        **
  7. **    WWWWW   IIIIIIII NN   NNN DDDDDDD  BBBBBBB  AA    AA SSSSSS  EEEEEEEE  **
  8. **                                                                           **
  9. **   SSSSSS  OOOOOO  FFFFFFFF TTTTTTTT WW     WW    AA    RRRRRRR  EEEEEEEE  **
  10. **  SS      OO    OO FF          TT    WW  W  WW  AA  AA  RR    RR EE        **
  11. **   SSSSS  OO    OO FFFFF       TT    WW  W  WW AAAAAAAA RRRRRRR  EEEEEE    **
  12. **       SS OO    OO FF          TT     WW W WW  AA    AA RR   RR  EE        **
  13. **  SSSSSS   OOOOOO  FF          TT      WWWWW   AA    AA RR    RR EEEEEEEE  **
  14. **                                                                           **
  15. *********** NOTICE ************************************************************
  16. **        This file contains valuable trade secrets and proprietary          **
  17. **        assets of Windbase Software Inc.  Embodying substantial            **
  18. **        creative efforts and confidential information.  Unauthorized       **
  19. **        use, copying, decompiling, translating, disclosure or              **
  20. **        transfer, of any kind, is strictly prohibited.                     **
  21. **                                                                           **
  22. **        COPYRIGHT (C) 1992, 1993, 1994.  Windbase Software Inc.            **
  23. **        ALL RIGHTS RESERVED.                                               **
  24. \*****************************************************************************/
  25.  
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <malloc.h>
  29.  
  30. #include "../memsl.h"
  31.  
  32. #if defined(WBTRC_LEVEL1) || defined(WBTRC_LEVEL2)
  33.   #ifdef WBSTDC
  34.     int main(int argc, char **argv)
  35.   #else
  36.     int main(argc, argv)
  37.       int argc;
  38.       char **argv;
  39.   #endif
  40. #else
  41.   #ifdef WBSTDC
  42.     int main(void)
  43.   #else
  44.     int main()
  45.   #endif
  46. #endif
  47.   {
  48.     FILE *file;
  49.     WBDQUEUE *dqueue;
  50.     char str[21], item[21], *strptr;
  51.  
  52.     WBTrcMainEntry();
  53.  
  54. #if 1  /* Dequeue using an array and having the dqueue copy the items */
  55.  
  56.     printf("Dequeue using an array:\n");
  57.     if ((dqueue = WBDQueueOpen(NULL,21,50,1)) != NULL)
  58.       {
  59.         if ((file = fopen("data.dat","r")) != NULL)
  60.           {
  61.             while (fgets(str,20,file))
  62.               {
  63.                 if (WBDQueuePushL(dqueue,str) == 0)
  64.                   {
  65.                     printf("Popping: %s",WBDQueuePopL(dqueue,item));
  66.                     WBDQueuePushR(dqueue,str);
  67.                   }
  68.               }
  69.             while ((strptr = WBDQueuePopR(dqueue,item)) != NULL)
  70.               printf("%s  %s",strptr, item);
  71.             fclose(file);
  72.           }
  73.     WBDQueueClose(dqueue);
  74.       }
  75. #else   /* Dequeue using a linked list */
  76.  
  77.     printf("Dequeue using a linked list:\n");
  78.     if ((dqueue = WBDQueueOpen(NULL,0,0,0)) != NULL)
  79.       {
  80.         if ((file = fopen("data.dat","r")) != NULL)
  81.           {
  82.             while (fgets(str,20,file))
  83.               {
  84.                 if ((strptr = malloc(strlen(str)+1)) != NULL)
  85.                   {
  86.                     strcpy(strptr,str);
  87.                     WBDQueuePushL(dqueue,strptr);
  88.                   }
  89.               }
  90.             fclose(file);
  91.             while ((strptr = WBDQueuePopL(dqueue,NULL)) != NULL)
  92.               {
  93.                 printf("%s",strptr);
  94.                 free(strptr);
  95.               }
  96.           }
  97.         WBDQueueClose(dqueue);
  98.       }
  99. #endif
  100.     WBTrcReturn(0,0,("0"));
  101.   }
  102.