home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!convex!darwin.sura.net!news.larc.nasa.gov!uakari.primate.wisc.edu!ames!purdue!sample.eng.ohio-state.edu!cis.ohio-state.edu!magnus.acs.ohio-state.edu!hshamans
- From: hshamans@magnus.acs.ohio-state.edu (Harry T Shamansky)
- Newsgroups: comp.sys.sgi
- Subject: Ssanf gobbles source string ??
- Keywords: sscanf
- Message-ID: <1992Sep3.153419.26116@magnus.acs.ohio-state.edu>
- Date: 3 Sep 92 15:34:19 GMT
- Sender: Harry Shamansky
- Distribution: comp.sys.sgi
- Organization: The Ohio State University
- Lines: 62
-
-
- Hello...
-
- I'm wondering if the sscanf should *ever* modify the string from which
- it is scanning. Here is a short code example of my question:
- (I'm on an Indigo running 4.0.2, with the Ansi C 1.1 loaded)
-
- ****************************** cut here *****************************
- #include <string.h>
- #include <stdio.h>
-
- main()
- {
- char test1[64],test2[64];
- int i;
-
- /* This segment of code alters the source string test1 */
- strcpy(test1,"2dfft 0");
- printf("Before %s\n",test1);
- sscanf(test1,"%s %i",test2,&i);
- printf("After %s\n",test1);
- printf(" values test2=%s , i= %l\n",test2,i);
-
- /* This segment of code does not alter the source string test1 */
- strcpy(test1,"2dfft 0 end");
- printf("Before %s\n",test1);
- sscanf(test1,"%s %i",test2,&i);
- printf("After %s\n",test1);
- printf(" values test2=%s , i= %i\n",test2,i);
-
- /* This segment of code does not alter the source string test1 */
- strcpy(test1,"2dfft 0");
- printf("Before %s\n",test1);
- sscanf(test1,"%s %l",test2,&i);
- printf("After %s\n",test1);
- printf(" values test2=%s , i= %i\n",test2,i);
-
- return;
- }
- ****************************** cut here *****************************
-
- The result of this code is:
-
- 176 bchan@coulomb:~> zz
- Before 2dfft 0
- After 2dfft
- values test2=2dfft , i=
- Before 2dfft 0 end
- After 2dfft 0 end
- values test2=2dfft , i= 0
- Before 2dfft 0
- After 2dfft 0
- values test2=2dfft , i= 0
-
- note that for the first case, the After result has been mangled, but
- the other cases seem O.K. Is this my stupidity, or is a bug lurking ?
- (the ^? was a funny double umlaut over the character y, if anyone cares)
-
- Thanks for any thoughts....
-
- Harry Shamansky .. hts@hertz.eng.ohio-state.edu
- Ben Chan .. bchan@coulomb.eng.ohio-state.edu
-