I've written some code that I believe is very close to the answer of the problem, but I can't seem to properly compare two characters. I don't know how to properly cast them.
I know how to do this using arrays, but I want to know how to do it using pointers.
char *FindToken(char *s,char *t)
{
while (s)
{
//char check = *(char*)s; tried this but it doesn't work
while(t)
{
if (strcmp(s,t)){
//return s;
printf("%s", s);
}
t++;
}
s++;
}
return NULL;
}
This is the original problem:
Write a
C functioncalled that accepts 2 parameters: anullterminated character array (string) called S in reference to the string to be searched, and a second string parameter calledT. Thestring Tis alist of characters(not including the ‘\0’) that are tokens, or characters to be searched for inS. Do not modify eitherSorT. It willreturna character pointer to the position of the first character inTthat is found inS, if it is found inS,orNULLotherwise.
For example:
printf("%s", *FindToken(“are exams over yet?”, “zypqt”)); // will display “yet?”
t++in line 12?:(t++);?strtokfunction. I think it going to help you.strcmpcompares the whole strings not characters.