home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / HLPAS2C.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  1.3 KB  |  48 lines

  1. /**
  2. *
  3. *  Name     HLPAS2C -- Convert a Pascal string to C format.
  4. *
  5. *  Synopsis    length = hlpas2c(ppascal_string, pc_string,
  6. *                 max_length);
  7. *
  8. *        int length            Length of C string,
  9. *                        including terminating '\0'.
  10. *        const char *ppascal_string  Pascal string to convert.
  11. *        char *pc_string         Buffer to place C string in.
  12. *        int max_length            Maximum length of C string,
  13. *                        including '\0'.
  14. *
  15. *
  16. *  Description    HLPAS2C will convert a Pascal-style string with leading
  17. *        length byte into a C-style '\0' terminated string.
  18. *        The maximum number of characters that will be written
  19. *        to pc_string will be max_length.
  20. *
  21. *  Returns    int length    The total length of the C string includng
  22. *                  the terminating '\0'.
  23. *
  24. *  Version    6.00 (C)Copyright Blaise Computing Inc.  1989
  25. *
  26. **/
  27. #include <bhelp.h>
  28. #include <string.h>
  29.  
  30. int hlpas2c(ppascal_string, pc_string, max_length)
  31. const char *ppascal_string;
  32. char *pc_string;
  33. int max_length;
  34. {
  35.     int c_length;
  36.     int temp_index;
  37.  
  38.     c_length = (int) ppascal_string[0] + 1;
  39.     c_length = (max_length > c_length) ? c_length
  40.                        : max_length;
  41.     ppascal_string++;
  42.     for (temp_index = 0; temp_index < (c_length - 1); temp_index++)
  43.     pc_string[temp_index] = ppascal_string[temp_index];
  44.     pc_string[c_length - 1] = '\0';
  45.  
  46.     return(c_length);
  47. }
  48.