Hmm, ok. Well, I'm not quite sure how you can compare this to something trivial as I'm sure it's very likely not from the experiences I've had in trying to convert these functions over the last few days.
Also, I am thinking you didnt understand what I had asked for. I'm interested in a RETURN string value or a pointer that can be turned into one I guess which is why I asked for utility functions, not a main loop. From what I've been reading, C cannot return strings, it can only return integers and thus thats why returning a pointer works I guess, since it's an integer that points at a memory address? I dont know how it all works, but thats my uneducated understanding of it. What you have here doesnt return anything, and it seems to be compiler dependent and not something I could turn into a utility function anyway without using a specific compiler. I use GNU's GCC on Linux and it was indeed undefined like you mentioned.
Also, I dont have any code to post because I havent the slightest clue on how this would be accomplished in C and I'm starting to think that it probably isnt even possible to begin with anyway. About the only thing I could post would be examples of how I want to use it, which I did post already. I've asked around a little on IRC but have had no luck in finding any real answer on how to convert these parsing functions to C. I use them daily with PHP and they are just awesome. I have not missed regex one bit since using these.
Oh and something else. I noticed that in your code, you hard coded the <test> </test> thing. Well, these are only example strings, the end results would obviously not be hard coded as such so that it could support any kind of opening/closing tag. I believe that this is probably far to complex for a simple solution and I may have to limp along with a before() or after() function that utilizes substr somehow. I dont want to have a 50000 line app just to facilitate a between() function. I'd be happy with a small 10 liner for either before() or after().
Anyway thanx for at least trying. But I dont think this would be the right answer.
Maybe the following code would make it more clear what I want? This code actually works, the only thing missing are the guts of the utility functions since I dont know what should go there. I dont know the difference between const char and char, either one seems to work. Is there any reason I should use one over the other?
Code:
char const * between(char const * this, char const * and_this, char const * in_this)
{
char const * return_val = this;
return return_val;
}
char const * before(char const * this, char const * in_this)
{
char const * return_val = this;
return return_val;
}
char const * after(char const * this, char const * in_this)
{
char const * return_val = this; //This is just an example, the return_val would actually be the result of the parsing code that goes in this function.
return return_val;
}
int main()
{
char const * this = "this";
char const * and_this = "and_this";
char const * in_this = "in this";
char const * between_test = "";
between_test = between(this, and_this, in_this);
puts(between_test);
}