Problem in sscanf with gcc-1.37 ?

lamarche at ireq.hydro.qc.ca lamarche at ireq.hydro.qc.ca
Fri Jul 27 13:40:27 AEST 1990


The following problem arrived when I tried to compile Dclock
(X11R4 client, comp.sources.x). Here is a short program that
describe it.

#include <stdio.h>
main  ()
{
   char works[] = "Works 1 2";
   char* fails = "Fails 1 2";
   int d1,d2;

   printf ( "String: %s ", works );
   fflush(stdout);
   sscanf ( works, "Works %1d %1d",  &d1, &d2 );
   printf ( "--> Read: %d %d\n", d1, d2 );

   printf ( "String: %s ", fails );
   fflush(stdout);
   sscanf ( fails, "Fails %1d %1d",  &d1, &d2 );
   printf ( "--> Read: %d %d\n", d1, d2 );
}

That gives the following output:
String: Works 1 2 --> Read: 1 2
String: Fails 1 2 Memory fault - core dumped

Conclusion:
We can printf <fail> but we can't sscanf it.

Since this program works with cc, is this behavior normal with gcc ? 
  
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
| Louis Lamarche, IREQ |       lamarche at ireq.hydro.qc.ca
| CP 1000, Varennes    |                 or
| QC, Canada, J3X 1S1  |  514-652-8077 (office)  514-324-2919 (home)



More information about the Comp.unix.aux mailing list