-
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.
-
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.
-
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);
}
-
Call me biased, but I also like sscanf.