Well then as it been said you could iterate bacward because starting from the end you will have less to count.
As a ideea when you hit the first '/' from the end then stop and replace the iterator position with a null terminated char then copyc until you find that null char, or use that position and make a strmid function something like substr.