home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc_prog / chap09 / strpool.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-06  |  1.0 KB  |  38 lines

  1. /* strpool.c  -- dumps the string pool to show how     */
  2. /*               quoted strings are stored             */
  3.  
  4. #define PHRASE \
  5. "This is one long sentence that the compiler \
  6. combines into a single string."
  7.  
  8. char Start[]        = "start";
  9. char Long_phrase[]  = PHRASE;
  10. char Short_phrase[] = "This is a short phrase";
  11. char Cent_string[]  = "\x9b";
  12.  
  13. main()
  14. {
  15.     static char local_phrase[] = "This is local";
  16.     char *cp;
  17.  
  18.     printf("Dump of the string pool:\n");
  19.     printf("-----------------------\n");
  20.  
  21.     printf("\"");                /* print leading quote */
  22.  
  23.     /*
  24.      * Note that the address of a string can be
  25.      * assigned to a pointer: cp = Start
  26.      */
  27.     for (cp = Start; *cp != '^'; ++cp)
  28.         {
  29.         if (*cp == '\0')        /* print '\0' as a quote */
  30.             printf("\"\n\"");
  31.         else if (*cp == '\n' )  /* print '\n' as '\' 'n' */
  32.             printf("\\n");
  33.         else
  34.             printf("%c", *cp);
  35.         }
  36.     printf("^");                /* marks end */
  37. }
  38.