sscanf always returns 0

View: New views
2 Messages — Rating Filter:   Alert me  

sscanf always returns 0

by David Grundberg-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi buglist,

Running

  [scanned, count, errmsg, offset] = sscanf ("56 foobar", "%d")

should give offset = 4 but instead I get offset = 0.

I changed octave_istrstream to fix this, see attachment.

Best regards,
David


# HG changeset patch
# User David Grundberg <davidg@...>
# Date 1257850593 -3600
# Node ID d83dd90b46debd8b2288a992e60cc78cf1089306
# Parent  2d19eb339df748f8dd776b6f7b804df7ffe66c5a
Fix fourth argument from sscanf

diff -r 2d19eb339df7 -r d83dd90b46de src/ChangeLog
--- a/src/ChangeLog Tue Nov 10 11:02:35 2009 +0100
+++ b/src/ChangeLog Tue Nov 10 11:56:33 2009 +0100
@@ -1,3 +1,8 @@
+2009-11-10  David Grundberg  <davidg@...>
+
+ * oct-strstrm.h (octave_base_strstream::tell): Declare virtual.
+ (octave_istrstream::tell): New method.
+
 2009-11-10  Jaroslav Hajek  <highegg@...>
 
  * ov-class.cc (octave_class::numel): Use base version if called from
diff -r 2d19eb339df7 -r d83dd90b46de src/oct-strstrm.h
--- a/src/oct-strstrm.h Tue Nov 10 11:02:35 2009 +0100
+++ b/src/oct-strstrm.h Tue Nov 10 11:56:33 2009 +0100
@@ -45,7 +45,7 @@
 
   // Return current stream position.
 
-  long tell (void);
+  virtual long tell (void);
 
   // The name of the file.
 
@@ -104,6 +104,8 @@
   std::istream *input_stream (void) { return &is; }
 
   std::ostream *output_stream (void) { return 0; }
+
+  long tell (void) { return is.tellg (); }
 
   std::streambuf *rdbuf (void) { return is ? is.rdbuf () : 0; }
 

_______________________________________________
Bug-octave mailing list
Bug-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/bug-octave

sscanf always returns 0

by John W. Eaton-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 10-Nov-2009, David Grundberg wrote:

| Running
|
|   [scanned, count, errmsg, offset] = sscanf ("56 foobar", "%d")
|
| should give offset = 4 but instead I get offset = 0.
|
| I changed octave_istrstream to fix this, see attachment.

I applied it.

Thanks,

jwe
_______________________________________________
Bug-octave mailing list
Bug-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/bug-octave