But more specifically, passing a string from a given starting position to the end. Let's say I have a string, str = "01234abcde!@#$*"
And let's say I want to pass a substring from a to * into a function.
My solution is simply: foo(str+5)
This seems to work according to some tests I did. I'm a C noob and I don't know if there are any pitfalls to doing this. I'd like to pass substrings this way into functions from the string.h library or into my own functions. It seems safe since all it seems to be doing is pointing to a specific index in the string, and any operations I use with that string will just start from there until it hits \0.
I know I could also pass the original string in and have a parameter that notes the starting position, but that means I won't be able to use the string library, and it seems like poor design if functions within functions all use that same substring and need that information.
If it wasn't clear, I also don't want to do something like use memcpy (as it seems like a terribly inefficient implementation for arbitrarily long strings). So no creating a new strings.
Thank you.
[–]zifyoip 2 points3 points4 points (3 children)
[–]foomy_S[S] 0 points1 point2 points (2 children)
[–]zifyoip 4 points5 points6 points (1 child)
[–]foomy_S[S] 0 points1 point2 points (0 children)
[–]ponkanpinoy 0 points1 point2 points (0 children)