home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / sscanf.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  2KB  |  77 lines

  1. /***
  2. *sscanf.c - read formatted data from string
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines scanf() - reads formatted data from string
  8. *
  9. *******************************************************************************/
  10.  
  11. #include <cruntime.h>
  12. #include <stdio.h>
  13. #include <dbgint.h>
  14. #include <stdarg.h>
  15. #include <string.h>
  16. #include <internal.h>
  17. #include <mtdll.h>
  18.  
  19. /***
  20. *int sscanf(string, format, ...) - read formatted data from string
  21. *
  22. *Purpose:
  23. *       Reads formatted data from string into arguments.  _input does the real
  24. *       work here.  Sets up a FILE so file i/o operations can be used, makes
  25. *       string look like a huge buffer to it, but _filbuf will refuse to refill
  26. *       it if it is exhausted.
  27. *
  28. *       Allocate the 'fake' _iob[] entryit statically instead of on
  29. *       the stack so that other routines can assume that _iob[] entries are in
  30. *       are in DGROUP and, thus, are near.
  31. *
  32. *       Multi-thread: (1) Since there is no stream, this routine must never try
  33. *       to get the stream lock (i.e., there is no stream lock either).  (2)
  34. *       Also, since there is only one staticly allocated 'fake' iob, we must
  35. *       lock/unlock to prevent collisions.
  36. *
  37. *Entry:
  38. *       char *string - string to read data from
  39. *       char *format - format string
  40. *       followed by list of pointers to storage for the data read.  The number
  41. *       and type are controlled by the format string.
  42. *
  43. *Exit:
  44. *       returns number of fields read and assigned
  45. *
  46. *Exceptions:
  47. *
  48. *******************************************************************************/
  49.  
  50. int __cdecl sscanf (
  51.         REG2 const char *string,
  52.         const char *format,
  53.         ...
  54.         )
  55. /*
  56.  * 'S'tring 'SCAN', 'F'ormatted
  57.  */
  58. {
  59.         va_list arglist;
  60.         FILE str;
  61.         REG1 FILE *infile = &str;
  62.         REG2 int retval;
  63.  
  64.         va_start(arglist, format);
  65.  
  66.         _ASSERTE(string != NULL);
  67.         _ASSERTE(format != NULL);
  68.  
  69.         infile->_flag = _IOREAD|_IOSTRG|_IOMYBUF;
  70.         infile->_ptr = infile->_base = (char *) string;
  71.         infile->_cnt = strlen(string);
  72.  
  73.         retval = (_input(infile,format,arglist));
  74.  
  75.         return(retval);
  76. }
  77.