what string function??

This is a discussion on what string function?? within the C Programming forums, part of the General Programming Boards category; 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 ...

  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
    cas
    cas is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    979
    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,006
    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, 01:11 AM
  5. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21