home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11539 < prev    next >
Encoding:
Text File  |  1992-07-23  |  1.9 KB  |  50 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!sun-barr!cs.utexas.edu!sdd.hp.com!ux1.cso.uiuc.edu!usenet.ucs.indiana.edu!navajo!shulick
  3. From: shulick@navajo.ucs.indiana.edu (Sam Hulick)
  4. Subject: HIgher problems at hand. HELP!
  5. Message-ID: <Brv6oD.Dq5@usenet.ucs.indiana.edu>
  6. Originator: shulick@navajo
  7. Sender: news@usenet.ucs.indiana.edu (USENET News System)
  8. Nntp-Posting-Host: navajo.ucs.indiana.edu
  9. Reply-To: shulick@navajo.ucs.indiana.edu
  10. Organization: Vallen Software
  11. Date: Thu, 23 Jul 1992 23:02:36 GMT
  12. Lines: 36
  13.  
  14.  
  15. int strstr(char *data, char *chunk)                          
  16. {                                                            
  17.         static int x;                                        
  18.                                                              
  19.         for (x=0;x<strlen(data); ++x)   {                    
  20.                 if (!strncmp(chunk, &data[x], strlen(chunk)))
  21.                         return x+1;                          
  22.         }                                                    
  23.         return 0;                                            
  24. }
  25.  
  26. What's wrong with this subroutine?  I'm making strstr() since Amiga C
  27. doesn't have it.
  28. I do stuff like ..  d  = strstr("foobar", "bar");
  29. and d comes up like 139579275 or some weird value, where it's SUPPOSED to
  30. return either 0 (not found) or some value x, where x is the position in the
  31. string where "bar" starts.  When I say
  32.  
  33. int strstr(char *data...
  34.  
  35. Can I pass both *str and str[25]?  For instance..
  36.  
  37.    char *blah;
  38.  
  39.    s = strstr(blah....  /* after malloc()'ing it, of course */
  40.  
  41.   or  char blah[50];  Could either blah be passed into strstr as a (char *)?
  42.  
  43. Again, reply via email, please.  shulick@indiana.edu
  44. Thanks.
  45.  
  46. -- 
  47. Sam Hulick  ///  E-mail: shulick@indiana.edu (including NeXT mail)
  48. ------------------------------------------------------------------------
  49.   "The pen is the mouth and the paper is the soon-to-be-wise one."
  50.