Pointers
Task: Use pointers to compare two sets of characters, a source string and a charSet string. Your program will include a function called searcher that uses pointers to both the source string and the character set, and which returns a pointer to a char.
The searcher function should use exactly this prototype (do not include any other parameters, and don't take advantage of any global variables in the searcher function):
char *searcher (char *source, char *charSet);
The basic idea is to locate the first character in the source string that matches any of the characters in thecharSet string. The function then returns a pointer to the place in source where the first match was found.
If none of the characters in source match any of the chars in charSet, then a NULL pointer is returned. Note that you are searching for a single character, not a substring, although what you will print is a substring. The calling program should use the pointer returned from searcher.
For example:
Suppose source points to: ABCBGFE
(a) If charSet points to XYZ, then NULL is returned.
(b) If charSet points to XREQCF, then the function should return a pointer to the letter C in source; the substring CBGFE will be printed.
(c) If charSet points to FFGG, then the function should return a pointer to the letter G in source; the substring GFE will be printed.
(d) If charSet points to GBF, then the function should return a pointer to the first letter B in source; the substring BCBGFE will be printed.
Constraints: This program is intended to provide practice with pointers, so these limitations will apply:
You may not use any C-string or string object commands. For example, strcpy, strcmp, strlen, etc., are all off-limits.
You may not use array subscripts (brackets) anywhere in the searcher function. Use pointer notation rather than array notation in that function. However, the input function may read strings into array variables, i.e., into C-strings.
Processing: The program should be interactive. The user will provide a source string and also a character set string. The program should continue processing strings until the user signals for completion.
Output: After each search, print the following summary:
the source string
the charSet string
the address of the source string
the substring of the source string that starts at the position found by searcher if the search was successful, or print "unsuccessful search"