* stdio-common/Makefile (tests): Add scanf[1-9].

* stdio-common/scanf[1-9].c: New files.  Bug tests from hjl.
Wed Jan 24 03:22:07 1996  Roland McGrath  <roland@churchy.gnu.ai.mit.edu>

	* stdio-common/Makefile (tests): Add scanf[1-9].
	* stdio-common/scanf[1-9].c: New files.  Bug tests from hjl.
This commit is contained in:
Roland McGrath 1996-01-24 08:23:33 +00:00
parent 0793d3483a
commit a66067befe
11 changed files with 201 additions and 1 deletions

View File

@ -1,3 +1,8 @@
Wed Jan 24 03:22:07 1996 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
* stdio-common/Makefile (tests): Add scanf[1-9].
* stdio-common/scanf[1-9].c: New files. Bug tests from hjl.
Wed Jan 24 04:18:36 1996 Paul Eggert <eggert@twinsun.com>
* strftime.c (strftime):

View File

@ -40,7 +40,8 @@ tests := tst-printf tstscanf test_rdwr test-popen tstgetln test-fseek \
temptest tst-fileno test-fwrite \
xbug errnobug \
bug1 bug2 bug3 bug4 bug5 bug6 bug7 bug8 bug9 bug10 bug11 \
tfformat tiformat tstdiomisc
tfformat tiformat tstdiomisc \
scanf1 scanf2 scanf3 scanf4 scanf5 scanf6 scanf7 scanf8 scanf9
include ../Rules

15
stdio-common/scanf1.c Normal file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
#include <stdlib.h>
int
main()
{
int i,n,r;
n = i = r = -1;
r = sscanf("1234:567", "%d%n", &i, &n);
printf("%d %d %d\n", r, n, i);
if (r != 1 || i != 1234 || n != 4)
abort ();
return 0;
}

24
stdio-common/scanf2.c Normal file
View File

@ -0,0 +1,24 @@
#include <stdio.h>
#include <stdlib.h>
main()
{
int point, x, y;
point = x = y = -1;
sscanf("0x10 10", "%x %x", &x, &y);
printf("%d %d\n", x, y);
if (x != 0x10 || y != 0x10)
abort ();
point = x = y = -1;
sscanf("P012349876", "P%1d%4d%4d", &point, &x, &y);
printf("%d %d %d\n", point, x, y);
if (point != 0 || x != 1234 || y != 9876)
abort ();
point = x = y = -1;
sscanf("P112349876", "P%1d%4d%4d", &point, &x, &y);
printf("%d %d %d\n", point, x, y);
if (point != 1 || x != 1234 || y != 9876)
abort ();
return 0;
}

30
stdio-common/scanf3.c Normal file
View File

@ -0,0 +1,30 @@
#include <stdio.h>
#include <stdlib.h>
int main(int arc, char *argv)
{
int n, res;
unsigned int val;
char *s;
s = "111";
val = n = -1;
res = sscanf(s, "%u %n", &val, &n);
printf("Result of sscanf = %d\n", res);
printf("Scanned format %%u = %u\n", val);
printf("Possibly scanned format %%n = %d\n", n);
if (n != 3 || val != 111 || res != 1)
abort ();
val = n = -1;
res = sscanf(s, "%u%n", &val, &n);
printf("Result of sscanf = %d\n", res);
printf("Scanned format %%u = %u\n", val);
printf("Possibly scanned format %%n = %d\n", n);
if (n != 3 || val != 111 || res != 1)
abort ();
return 0;
return 0;
}

30
stdio-common/scanf4.c Normal file
View File

@ -0,0 +1,30 @@
#include <stdio.h>
int main(int arc, char *argv)
{
int n, res;
unsigned int val;
FILE *fp = fopen ("/dev/null", "r");
val = 0;
res = fscanf(fp, "%n", &val);
printf("Result of fscanf %%n = %d\n", res);
printf("Scanned format = %d\n", val);
res = fscanf(fp, "");
printf("Result of fscanf \"\" = %d\n", res);
if (res != 0)
abort ();
res = fscanf(fp, "BLURB");
printf("Result of fscanf \"BLURB\" = %d\n", res);
if (res >= 0)
abort ();
fclose (fp);
return 0;
return 0;
}

20
stdio-common/scanf5.c Normal file
View File

@ -0,0 +1,20 @@
#include <stdio.h>
int
main()
{
int a, b;
a = b = -1;
sscanf ("12ab", "%dab%n", &a, &b);
printf ("%d, %d\n", a, b);
if (a != 12 || b != 4)
abort ();
a = b = -1;
sscanf ("12ab100", "%dab%n100", &a, &b);
printf ("%d, %d\n", a, b);
if (a != 12 || b != 4)
abort ();
return 0;
}

15
stdio-common/scanf6.c Normal file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
#include <stdlib.h>
main ()
{
int n = -1;
char c = '!';
int ret;
ret = sscanf ("0x", "%i%c", &n, &c);
printf ("ret: %d, n: %d, c: %c\n", ret, n, c);
if (ret != 2 || n != 0 || c != 'x')
abort ();
return 0;
}

22
stdio-common/scanf7.c Normal file
View File

@ -0,0 +1,22 @@
#include <stdio.h>
#include <stdlib.h>
main ()
{
long long int n;
int ret;
n = -1;
ret = sscanf ("1000", "%lld", &n);
printf ("%%lld: ret: %d, n: %Ld, c: %c\n", ret, n);
if (ret != 1 || n != 1000L)
abort ();
n = -2;
ret = sscanf ("1000", "%llld", &n);
printf ("%%llld: ret: %d, n: %Ld\n", ret, n);
if (ret != 0 || n >= 0L)
abort ();
return 0;
}

15
stdio-common/scanf8.c Normal file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
main ()
{
int ret;
char buf [1024] = "Ooops";
ret = sscanf ("static char Term_bits[] = {", "static char %s = {", buf);
printf ("ret: %d, name: %s\n", ret, buf);
if (ret != 1 || strcmp (buf, "Term_bits[]") != 0)
abort ();
return 0;
}

23
stdio-common/scanf9.c Normal file
View File

@ -0,0 +1,23 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
int matches;
char str[10];
str[0] = '\0';
matches = -9;
matches = sscanf("x ]", "%[^] ]", str);
printf("Matches = %d, string str = \"%s\".\n", matches, str);
printf("str should be \"x\".\n");
if (strcmp (str, "x")) abort ();
str[0] = '\0';
matches = -9;
matches = sscanf(" ] x", "%[] ]", str);
printf("Matches = %d, string str = \"%s\".\n", matches, str);
printf("str should be \" ] \".\n");
if (strcmp (str, " ] ")) abort ();
exit(0);
return 0;
}