Thread: substrings

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #12
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    Code:
    const char *substr(const char *s, const char *match)
    {
      do {
        const char *p, *q;
        //if both strings match it'll end up comparing chars after the string's end
        for (p = s, q = match; *p == *q && *q!=0 ; p++, q++)
          ;
        if (*q == '\0')
          return s;
      } while (++*s != '\0');//i think we want to know if the next char is valid, not the actual
    
      return 0;
    }
    Did I just try to fix Prelude's code ?!?
    Last edited by xErath; 06-02-2005 at 07:42 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help, extracting substrings from a string
    By doubty in forum C Programming
    Replies: 1
    Last Post: 06-17-2009, 11:57 PM
  2. Need help on substrings and streams
    By TaiL in forum C++ Programming
    Replies: 2
    Last Post: 10-08-2008, 06:18 PM
  3. vector of substrings
    By manav in forum C++ Programming
    Replies: 47
    Last Post: 05-10-2008, 02:05 PM
  4. Searching for a series of possible substrings inside a string
    By andrew.bolster in forum C Programming
    Replies: 7
    Last Post: 02-10-2008, 02:20 AM
  5. Searching strings - substring's
    By Vber in forum C Programming
    Replies: 4
    Last Post: 02-06-2003, 12:05 PM