fscanf question & further puzzle

Shane Dawalt sdawalt at wright.EDU
Sat Dec 30 07:32:04 AEST 1989


in article <13805 at reed.UUCP>, kab at reed.bitnet (Kent Black,L08,640,7754072) says:
> 
> I dislike [fs]?scanf, and rarely use any of them, but bear with me for
> NEW and IMPROVED adventures of format troubles.
> 

   Normally, these functions are used for computer generated output like
lists of numbers.  They are definitely not suited for human input.  I am
using sscanf() to tear apart plot data in SPICE output files.  Works real
nice.

> 
> However, the manual says you can specify an alternate "scanset" with
> brackets.  This might be useful if you know the data is formatted with
> strict columns (not something I would want to depend upon, but by way of
> example, besides which, Mr. Smith's code is so formatted).  So it seems
> we could use:
> 	...
>         fscanf(stream,"%30[ a-zA-Z]s%30[ a-zA-Z]s",instr1,instr2);
>         printf("'%s':'%s'\n", instr1, instr2);
> 	...
>
  Your problem is that you didn't catch a subtle hint in the manual.  The
brackets _replace_ the 's' type character.  Therefore, modify your fscanf
control string as shown below and it will work as expected.

	fscanf(stream,"%30[ a-zA-Z]%30[ a-zA-Z]",instr1,instr2);

  Shane

email: sdawalt at cs.wright.edu
       71076.511 at compuserve.com



More information about the Comp.lang.c mailing list