I just want to know is it a good way of programming style.
I know what is happening in this piece of code. look for the first occurrence of href save it next_next and then look for the first occurrence of "}" and save it end_marker.
Here my question is end_marker[-1] = '\0'; is needed? Because strstr, upon successful completion, strstr() shall return a pointer to the located string or a null pointer if the string is not found.
I know the endmarker '\0' is for string but don't know is it good to index the array in the negative number?
Code:
char *end_marker;
char *next_next = strstr(links_ptr, "href");
if (next_next != NULL) {
next_next += 7;
end_marker= strstr(next_next, "}");
end_marker[-1] = '\0'; // :)
}
EDIT: links_ptr contains this data
"links": [
{
"rel": "next",
"href": "https://www.randomstuff.com/blabla"
}
]