Question: Problem 1 : Write a function that will search a string for any one of a given set of characters. Your function should match this
Problem :
Write a function that will search a string for any one of a given set of characters.
Your function should match this prototype:
char findcharchar const source char const chars;
The basic idea is to locate the first character in the source string that
matches any of the characters in the chars 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, then a NULL pointer is returned. If
either argument is NULL, or either string is empty, then a NULL pointer is returned.
To illustrate, suppose source points to ABCDEDG. If chars points to JURY,
or QQQQ the function should return NULL. If chars points to XRCQEF, the function
should return a pointer to the C in source. The strings that the arguments point to
are never modified.
As it happens, there is a function in the C library called strpbrk that behaves
almost exactly the same as the one you are to write. But the object of this program
is for you to manipulate the pointers yourself, so
a You may not use any of the library string routines for example, strcpy strcmp
index, etc. and
b you may not use subscripts anywhere in your function.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
