bug in sscanf (scanf)?

Martin Wilde martin at zeus.hf.intel.com
Thu Nov 17 04:51:56 AEST 1988


I have a small fragment of code that does not work on V.3.2 386 UNIX. 
The problem appears to be in sscanf (scanf).   The following fragment of
code shows the problem.


main(argc, argv)
int	argc;
char	**argv;
{
	char	optarg[1024];
	int	times;
	char	s1[40], s2[40], s3[40], s4[255];

	(void) strcpy(optarg, argv[1]);
	(void) sscanf(optarg, "%d %s %s %s %255[^\0]", &times, s1, s2, s3, s4);
	(void) printf("times = %d, s1 = %s, s2 = %s, s3 = %s, s4 = %s\n", 
			times, s1, s2, s3, s4);
}

The invocation is:

     a.out "1 10 0L 1000L 31 32 33"

The output under XENIX III and XENIX V is:

    times = 1, s1 = 10, s2 = 0L, s3 = 1000L, s4 = 31 32 33

under V.3.2 is:

    times = 1, s1 = 10, s2 = 0L, s3 = 1000L, s4 =


wheres the last string in v.3.2?

what the sscanf is trying to do for s4 is take all the characters up until
the end of string (\0) and place them in s4, but do not exceed 255 characters
(don't want core dumps).  After RTFM, there does not seem to be a problem
doing this.

Does sscanf (scanf) have a problem?  Could it be reading up until the end of
string and then returning EOF (what the manual says) and ignoring that my
stop character is the EOF?

I do have a work around to the problem, but I donot like the inconsistencies.

Thanks....

                          
                  _/_          |
 ______  __.  __  /  o ____    |  textronix!reed!littlei!zeus:martin
/ / / <_(_/|_/ (_<__<_/ / <    |



More information about the Comp.bugs.sys5 mailing list