Let's say I have "game.abc" as a string (array of chars) and I want to get the chars that are before the dot. What you would deem to be the most efficient way to do this in C?
Is a "while until . copy char to char" the way to go or is there any other way?
I hope this question can help others also.
Thanks!
you can also use strchr() followed by strncpy() to find first instance of '.' in your string and then copy all characters before it to another string
It depends on what you're trying to optimize for. If for readability an ease of understanding/maintaining, then binW's suggestion is correct.
If you're chasing cycles and only want to visit each character of the input once, then it's better to do the two operations (searching for the dot and copying) in parallel as you suggest by doing them both in the same loop.
Note that the latter smells very much of premature optimization though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With