If I have a C string that contains *’s and I want to find the position of the 3 star in this string. What is the best/ more efficient way to do it other than going through a loop and checking char by char?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You probably want to do the searching with
strchr. Since you want the third instance of the character, you’ll still execute that in a loop.Whether this will actually be more efficient than writing a loop on your own may be open to some question, but it probably won’t be any slower, and the intent will be more clear to anybody reading the code.