TheTraveller
Programmer
Hello,
Disclaimer: I am trying to do this for a homework assignment, so please do not outright tell me how to code my solution.
I have been tasked by my instructor to write a function that compares string1 with string2. I am to take out of string1 whatever is not in string2.
Noting the various functions in the string.h library, I could not determine which one(s) I would need to use, if any.
I noted "strspn" as a good way to determine the first character in the "said" string that differs from the other, however I have noted that the "strtok" function seems to be my best bet, since I can continually search one string for "tokens" that are not in the other string.
Here is my problem. The strtok function returns a "pointer" to the first character in the token that differs from the other string. The function then places a NULL character immediately after the subscript that the pointer "points" to, replacing whatever character was in its place.
How can I utilize this pointer return value from the strtok function to my advantage? In other words, how can I use this pointer as a basis to then get the rest of the "token", if a NULL character is placed immediately after the subscript that the pointer points to?
Any feedback would be most appreciated. Thank you in advance.
The Traveller
Disclaimer: I am trying to do this for a homework assignment, so please do not outright tell me how to code my solution.
I have been tasked by my instructor to write a function that compares string1 with string2. I am to take out of string1 whatever is not in string2.
Noting the various functions in the string.h library, I could not determine which one(s) I would need to use, if any.
I noted "strspn" as a good way to determine the first character in the "said" string that differs from the other, however I have noted that the "strtok" function seems to be my best bet, since I can continually search one string for "tokens" that are not in the other string.
Here is my problem. The strtok function returns a "pointer" to the first character in the token that differs from the other string. The function then places a NULL character immediately after the subscript that the pointer "points" to, replacing whatever character was in its place.
How can I utilize this pointer return value from the strtok function to my advantage? In other words, how can I use this pointer as a basis to then get the rest of the "token", if a NULL character is placed immediately after the subscript that the pointer points to?
Any feedback would be most appreciated. Thank you in advance.
The Traveller