home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / sgi / 13238 < prev    next >
Encoding:
Text File  |  1992-09-03  |  2.2 KB  |  75 lines

  1. 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
  2. From: hshamans@magnus.acs.ohio-state.edu (Harry T Shamansky)
  3. Newsgroups: comp.sys.sgi
  4. Subject: Ssanf gobbles source string ??
  5. Keywords: sscanf
  6. Message-ID: <1992Sep3.153419.26116@magnus.acs.ohio-state.edu>
  7. Date: 3 Sep 92 15:34:19 GMT
  8. Sender: Harry Shamansky
  9. Distribution: comp.sys.sgi
  10. Organization: The Ohio State University
  11. Lines: 62
  12.  
  13.  
  14.   Hello...
  15.  
  16.   I'm wondering if the sscanf should *ever* modify the string from which
  17.   it is scanning. Here is a short code example of my question:
  18.   (I'm on an Indigo running 4.0.2, with the Ansi C 1.1 loaded)
  19.  
  20. ****************************** cut here *****************************
  21. #include <string.h>
  22. #include <stdio.h>
  23.  
  24. main()
  25. {
  26.   char test1[64],test2[64];
  27.   int i;
  28.  
  29.   /* This segment of code alters the source string test1 */
  30.   strcpy(test1,"2dfft 0");
  31.   printf("Before %s\n",test1);
  32.   sscanf(test1,"%s %i",test2,&i);
  33.   printf("After %s\n",test1);
  34.   printf(" values test2=%s , i= %l\n",test2,i);
  35.  
  36.   /* This segment of code does not alter the source string test1 */
  37.   strcpy(test1,"2dfft 0 end");
  38.   printf("Before %s\n",test1);
  39.   sscanf(test1,"%s %i",test2,&i);
  40.   printf("After %s\n",test1);
  41.   printf(" values test2=%s , i= %i\n",test2,i);
  42.  
  43.   /* This segment of code does not alter the source string test1 */
  44.   strcpy(test1,"2dfft 0");
  45.   printf("Before %s\n",test1);
  46.   sscanf(test1,"%s %l",test2,&i);
  47.   printf("After %s\n",test1);
  48.   printf(" values test2=%s , i= %i\n",test2,i);
  49.  
  50.   return;
  51. }
  52. ****************************** cut here *****************************
  53.  
  54.   The result of this code is:
  55.  
  56. 176 bchan@coulomb:~> zz
  57. Before 2dfft 0
  58. After 2dfft 
  59.  values test2=2dfft , i=
  60. Before 2dfft 0 end
  61. After 2dfft 0 end
  62.  values test2=2dfft , i= 0
  63. Before 2dfft 0
  64. After 2dfft 0
  65.  values test2=2dfft , i= 0
  66.  
  67.   note that for the first case, the After result has been mangled, but
  68.   the other cases seem O.K.  Is this my stupidity, or is a bug lurking ?
  69.   (the ^? was a funny double umlaut over the character y, if anyone cares)
  70.  
  71.   Thanks for any thoughts....
  72.  
  73.   Harry Shamansky  ..  hts@hertz.eng.ohio-state.edu
  74.   Ben Chan  ..  bchan@coulomb.eng.ohio-state.edu
  75.