[Solved] Finding the first char in a string using pointers [closed]


You probably intended to do this:

char* contains(const char* string, char c) {

  for (; *string; string++) {
    if (*string == c) {
      return string;
    }
  }
  return NULL;
}

Actually this boils more or less down to:

char* contains(const char* string, char c) {
    return strchr(string, c);
}

Your contains function does the same thing as strchr.

3

solved Finding the first char in a string using pointers [closed]