home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 5.ddi / CLIBSRC2.ZIP / SSCANF.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  3.2 KB  |  112 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - sscanf.c
  3.  *
  4.  * function(s)
  5.  *        Get     - gets a character from a string
  6.  *        UnGet   - ungets a character from a string
  7.  *        sscanf  - gets formatted input from a string
  8.  *        vsscanf - gets formatted input from a string
  9.  *-----------------------------------------------------------------------*/
  10.  
  11. /*
  12.  *      C/C++ Run Time Library - Version 5.0
  13.  *
  14.  *      Copyright (c) 1987, 1992 by Borland International
  15.  *      All Rights Reserved.
  16.  *
  17.  */
  18.  
  19.  
  20. #include <stdarg.h>
  21. #include <stdio.h>
  22. #include <_scanf.h>
  23.  
  24. /*---------------------------------------------------------------------*
  25.  
  26. Name            Get - gets a character from a string
  27.  
  28. Usage           static  int    Get(char **strPP)
  29.  
  30. Description     gets a character from a string
  31.  
  32. Return value    the character read or -1 of the null character
  33.  
  34. *---------------------------------------------------------------------*/
  35. static int near Get(char **strPP)
  36. {
  37.         register    unsigned  char  c;
  38.  
  39.         return  ((c = *((*strPP) ++)) == 0) ? -1 : c;
  40. }
  41.  
  42.  
  43. /*---------------------------------------------------------------------*
  44.  
  45. Name            UnGet - ungets a character from a string
  46.  
  47. Usage           static  void    UnGet(char c, char **strPP)
  48.  
  49. Description     decrements a character pointer
  50.  
  51. *---------------------------------------------------------------------*/
  52. #pragma argsused
  53. static void near UnGet(char c, char **strPP)
  54. {
  55.         --(*strPP);         /* ignore c, we don't allow the string to change */
  56. }
  57.  
  58.  
  59. /*---------------------------------------------------------------------*
  60.  
  61. Name            sscanf - gets formatted input from a string
  62.  
  63. Usage           int sscanf(const char *string,
  64.                            const char *format[, argument ...])
  65.  
  66. Prototype in    stdio.h
  67.  
  68. Description     gets formatted input from a string
  69.  
  70. Return value    number of fields scanned and stored.  sscanf returns EOF
  71.                 if an attempt is made to read at end-of-string
  72.  
  73. *---------------------------------------------------------------------*/
  74. int cdecl _FARFUNC sscanf(const char *buf, const char *fmt, ...)
  75. {
  76.         return  _scanner (
  77.                 (int near (*)(void *))Get,
  78.                 (void near (*)(int, void *))UnGet,
  79.                 &buf,
  80.                 fmt,
  81.                 _va_ptr
  82.                 );
  83. }
  84.  
  85.  
  86. /*---------------------------------------------------------------------*
  87.  
  88. Name            vsscanf - gets formatted input from a string
  89.  
  90. Usage           int vsscanf(const char *string,const char *format,
  91.                             va_list argp)
  92.  
  93. Prototype in    stdio.h
  94.  
  95. Description     gets formatted input from a string
  96.  
  97. Return value    number of fields scanned and stored.  vsscanf returns EOF
  98.                 if an attempt is made to read at end-of-string
  99.  
  100. *---------------------------------------------------------------------*/
  101.  
  102. int cdecl _FARFUNC vsscanf(const char *buf, const char *fmt, va_list ap)
  103. {
  104.         return  _scanner(
  105.                 (int near (*)(void *))Get,
  106.                 (void near (*)(int, void *))UnGet,
  107.                 &buf,
  108.                 fmt,
  109.                 ap
  110.                 );
  111. }
  112.