home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / libg++-2.7.1-base.tgz / libg++-2.7.1-src.tar / fsf / libg++ / libio / tests / tstdiomisc.c < prev    next >
C/C++ Source or Header  |  1995-04-25  |  683b  |  44 lines

  1. #ifndef STDIO_H
  2. #define STDIO_H <iostdio.h>
  3. #endif
  4. #include STDIO_H
  5.  
  6. void
  7. t1 ()
  8. {
  9.   int n = -1;
  10.   sscanf ("abc  ", "abc %n", &n);
  11.   printf ("t1: count=%d\n", n);
  12. }
  13.  
  14. void
  15. t2 ()
  16. {
  17.   int n;
  18.   long N;
  19.   int retval;
  20. #define SCAN(INPUT, FORMAT, VAR) \
  21.   VAR = -1; \
  22.   retval = sscanf (INPUT, FORMAT,  &VAR); \
  23.   printf ("sscanf (\"%s\", \"%s\", &x) => %d, x = %ld\n", \
  24.       INPUT, FORMAT, retval, VAR);
  25.  
  26.   SCAN ("12345", "%ld", N);
  27.   SCAN ("12345", "%llllld", N);
  28.   SCAN ("12345", "%LLLLLd", N);
  29.   SCAN ("test ", "%*s%n",  n);
  30.   SCAN ("test ",   "%2*s%n",  n);
  31.   SCAN ("12 ",   "%l2d",  n);
  32.   SCAN ("12 ",   "%2ld",  N);
  33. }
  34.  
  35. int
  36. main ()
  37. {
  38.   t1 ();
  39.   t2 ();
  40.  
  41.   fflush (stdout);
  42.   return 0;
  43. }
  44.