[C language] how to find index number (from 1) in new string.
Example : First, I have a string = 'stayhome' Then, the new string is 'eomhyast' So, the index of new string (from 1) : e = 1, o = 2, m = 3, etc. I want the output is the index of first string, but use the sequence of the second string So, if the string is 'stayhome', then index s = 7, t = 8, a = 6, y = 5, etc. So, if I input : stayhome eomhyast Then, the output : 7 8 6 5 4 2 3 1
1/13/2021 7:07:35 AMBriana
8 AnswersNew Answer
Are you supposed to read the inputs for the 2 strings, or are they hardcoded? I have the code ready, but I'd like to see your code first : ) Hint: Use strchr() from <string.h>
Arsenic And I have no idea how hashing is used in C LOL 😁
Ipang that's interesting. How didn't I thought of strchar() ? I have used hashing instead.😅
That's right NotAPythonNinja Duplicate letter or digit in either string (with same letter cases for alphabets) is indeed not suitable for strchr().
Briana check this out 👇 https://code.sololearn.com/cBZam3lep7Eu/?ref=app But as NotAPythonNinja and Ipang said, things will get different when duplicates and different case characters come into play. For now this only works with lower case English alphabets [a-z].
Ipang how to find all index with strchr? I only know how to find position of a certain alphabeth
Ipang here is a way to get all indexes of a char in a str. You could use strchr() as well if you want to. https://code.sololearn.com/ca12385A24A2/?ref=app // no error check
Briana Where is your code? I've been waiting ... Use pointer arithmetic to get distance of a certain char from the string beginning. From there add 1 to the distance, because you wanted base 1 index. I have commented the code, and made adjustments to allow duplicate letters. https://code.sololearn.com/cNpCyPg4h0r3/?ref=app