- #1
magnifik
- 360
- 0
I have an original code that searches through "s" for a specific character then stores this into a pointer (otherwise, null). This is the original code:
I need to rewrite it so it does the same thing but does NOT use any square brackets nor any integer variable. Here is what I have, but I am unsure of whether or not it is entirely correct;
Code:
const char* findMe(const char s[], char c)
{
for (int k = 0; s[k] != 0; k++)
if (s[k] == c)
return &s[k];
return NULL;
}
I need to rewrite it so it does the same thing but does NOT use any square brackets nor any integer variable. Here is what I have, but I am unsure of whether or not it is entirely correct;
Code:
const char* findMe(const char* s, char c)
{
while (*s != '\0')
{
if (*s == c)
return &s;
}
return NULL;
}