Thread: what string function??

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    26

    what string function??

    Example:
    I have a string with this "<a href="www.somesite.com">Somesite</a>"

    with strstr(str,str1);
    I can find where href starts.
    Now what C string function can I use to go from the href through the FIRST occurance of ">"

    So basically I'd like to find the next ">" in that string from "href" but not the one after the </a">" or any other trailing greater than signs.

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Omaha, Nebraska
    Posts
    116
    Code:
    int c;
    
    while((c = getchar()) != EOF)
    {
            if(c == '>')
             {
                    c == '  ';
             }
    }
    something like that should do it.
    there might be a function for it, but I'm not sure what it is.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    Use strchr() to find a character in a string. If you have a pointer to the href, that counts as a string, so you can use strchr() to search from that location to the next '>'.
    Code:
    char url[] = "<a href=\"www.somesite.com\">Somesite</a>";
    char *s, *p;
    s = strstr(url, "href");
    if(s != NULL)
    {
      p = strchr(s, '>');
      if(p != NULL) *p = 0; /* or do whatever you want; this modifies the original string */
      puts(s);
    }

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Call me biased, but I also like sscanf.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  3. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  4. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  5. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM