Back to index

glibc  2.9
Classes | Defines | Functions | Variables
tst-sscanf.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <locale.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  test

Defines

#define CHAR   char
#define L(str)   str
#define SSCANF   sscanf

Functions

int main (void)

Variables

const CHARstr_double []
const double val_double []
const CHARstr_long []
const CHARfmt_long []
const long int val_long []
struct test int_tests []

Class Documentation

struct test

Definition at line 27 of file runptests.c.

Class Members
int end
const CHAR * fmt
size_t offset
int options
const char * reg
double result
int retval
int start
const char * str
const CHAR * str

Define Documentation

#define CHAR   char

Definition at line 25 of file tst-sscanf.c.

#define L (   str)    str

Definition at line 26 of file tst-sscanf.c.

#define SSCANF   sscanf

Definition at line 27 of file tst-sscanf.c.


Function Documentation

int main ( void  )

Definition at line 114 of file tst-sscanf.c.

{
  double d[6];
  long l[6];
  int i, j;
  int tst_locale;
  int result = 0;

  tst_locale = 1;
  if (tst_locale)
    if (setlocale (LC_ALL, "en_US.ISO-8859-1") == NULL)
      {
       puts ("Failed to set en_US locale, skipping locale related tests");
       tst_locale = 0;
      }

  for (i = 0; i < 4; ++i)
    {
      if (SSCANF (str_double[i], L("%11lf%11lf%11lf%11lf%11lf%11lf"),
                &d[0], &d[1], &d[2], &d[3], &d[4], &d[5]) != 6)
       {
         printf ("Double sscanf test %d wrong number of "
                "assigned inputs\n", i);
         result = 1;
       }
      else
       for (j = 0; j < 6; ++j)
         if (d[j] != val_double[6 * i + j])
           {
             printf ("Double sscanf test %d failed (%g instead of %g)\n",
                    i, d[j], val_double[6 * i + j]);
             result = 1;
             break;
           }
    }

  for (i = 0; i < 4; ++i)
    {
      if (SSCANF (str_long[i], fmt_long[i],
                &l[0], &l[1], &l[2], &l[3], &l[4], &l[5]) != 6)
       {
         printf ("Integer sscanf test %d wrong number of "
                "assigned inputs\n", i);
         result = 1;
       }
      else
       for (j = 0; j < 6; ++j)
         if (l[j] != val_long[j])
           {
             printf ("Integer sscanf test %d failed (%ld instead %ld)\n",
                    i, l[j], val_long[j]);
             result = 1;
             break;
           }

      if (! tst_locale)
       break;
    }

  for (i = 0; i < sizeof (int_tests) / sizeof (int_tests[0]); ++i)
    {
      int dummy, ret;

      if ((ret = SSCANF (int_tests[i].str, int_tests[i].fmt,
                      &dummy)) != int_tests[i].retval)
       {
         printf ("int_tests[%d] returned %d != %d\n",
                i, ret, int_tests[i].retval);
         result = 1;
       }
    }

  for (i = 0; i < sizeof (double_tests) / sizeof (double_tests[0]); ++i)
    {
      double dummy;
      int ret;

      if ((ret = SSCANF (double_tests[i].str, double_tests[i].fmt,
                      &dummy)) != double_tests[i].retval)
       {
         printf ("double_tests[%d] returned %d != %d\n",
                i, ret, double_tests[i].retval);
         result = 1;
       }
    }

  return result;
}

Here is the call graph for this function:


Variable Documentation

Initial value:
{
  L("%9ld%9ld%9ld%9ld%9ld%9ld"),
  L("%I9ld%I9ld%I9ld%I9ld%I9ld%I9ld"),
  L("%'11ld%'11ld%'11ld%'11ld%'11ld%'11ld"),

}

Definition at line 55 of file tst-sscanf.c.

struct test int_tests[]
Initial value:
{
  L("-.10000E+020.20000E+020.25000E+010.40000E+010.50000E+010.12500E+01"),
  L("0.10000E+020.20000E+020.25000E+010.40000E+010.50000E+010.12500E+01"),
  L("-1234567E0198765432E0912345678901987654321091234567890198765432109"),

}

Definition at line 30 of file tst-sscanf.c.

Initial value:
{
  L("-12345678987654321123456789987654321123456789987654321"),
  L("-12345678987654321123456789987654321123456789987654321"),
  L("-12,345,678987,654,321123,456,789987,654,321123,456,789987,654,321"),

}

Definition at line 47 of file tst-sscanf.c.

const double val_double[]
Initial value:
{
  -.10000E+02, 0.20000E+02, 0.25000E+01, 0.40000E+01, 0.50000E+01, 0.12500E+01,
  0.10000E+02, 0.20000E+02, 0.25000E+01, 0.40000E+01, 0.50000E+01, 0.12500E+01,
  -1234567E01, 98765432E09, 12345678901.0, 98765432109.0, 12345678901.0,
    98765432109.0,
  -0.1000E+02, 0.20000E+02, 0.25000E+01, 0.40000E+01, 0.50000E+01, 0.12500E+01
}

Definition at line 38 of file tst-sscanf.c.

const long int val_long[]
Initial value:
{
  -12345678, 987654321, 123456789, 987654321, 123456789, 987654321
}

Definition at line 63 of file tst-sscanf.c.