I have two strings, e.g.:
str1 = "aaabbbcccdddeee"str2 = "aaabbbccc"
How to do something like str1 - str2 to get the dddeee substring?
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.
If
str2is guaranteed to be a prefix ofstr1, then this will suffice:which is equivalent to this: (as @James points out in the comments)
Of course,
str3is just a pointer into one of the original strings. If the contents of the original string changes, then so will your result. So you may want to create a copy, usingmalloc()andstrcpy()(and thenfree()at some point).