[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference hydra::amiga_v1

Title:AMIGA NOTES
Notice:Join us in the *NEW* conference - HYDRA::AMIGA_V2
Moderator:HYDRA::MOORE
Created:Sat Apr 26 1986
Last Modified:Wed Feb 05 1992
Last Successful Update:Fri Jun 06 1997
Number of topics:5378
Total number of notes:38326

4098.0. "Lattice and scanf()" by POBOX::ANDREWS (I'm the NRA) Tue Sep 11 1990 05:51

    I am having a strange problem with Lattice 5.05
    
    I am trying to read in a name, ended by a \ and am getting stung
    someplace
    strange.  Does Lattice allow you to use this?  It would seem not, but
    it is defined in my K&R book as valid.
    scanf("%s %[^\\]\\\n",firstname,lastname)
    But, it doesn't seem to allow the brackets.
    The lattice manual on fscanf,scanf, and sscanf doesn't mention them at
    all
    ************************************
    #include <stdio.h>
    
    main()
    {
    char firstname[80];	/* Room for the first name	*/
    char lastname[80];	/* Room for the last name	*/
    
    
    	/*
    	Keep reading names until reach EOF. Store the first string
            in firstname, skip any spaces,store everything until it
    	reaches a backslash in lastname, then finally skip the back-
    	slash and any newline it may find.  This is because there might
    	be more than one line in the file.
    	*/
    	while( scanf("%s %[^\\]\\\n",firstname,lastname) != EOF)
    		/*
    		print the name in the format lastname, first letter
    		of firstname
    		*/
    		printf("%s, %s.\n",lastname,firstname);
    	 /* Keep looping until EOF */
    }
    ************************************
    Input file
    Harry Caldwell\Maryann Thompson\Susan Martin\Terry Walters\
    Donald Anderson\Joseph Porter\
    Samuel Barten\
    Tim Ringer\Allison Ripley\Harriet Finch\
    ************************************
    Program output
    , Harry.
    , aldwell\Maryann.
    , hompson\Susan.
    , artin\Terry.
    , alters\.
    , onald.
    , nderson\Joseph.
    , orter\.
    , amuel.
    , arten\.
    , im.
    , inger\Allison.
    , ipley\Harriet.
    , inch\.
    
    
T.RTitleUserPersonal
Name
DateLines
4098.1K & R says a lot of things...WBC::BAKERWhatever happened to Fay Wrey...Tue Sep 11 1990 14:458
	I haven't tried using \ specifically, I but I know
	(from sad experience) that the exact set of features
	supported by scanf/sscanf/fscanf varies widely from
	compiler to compiler.  Once you go beyond the vanilla
	stuff, you're kind of on your own...

	~art