Menu
Coddy logo textTech

First Occurrence in String

Lesson 6 of 15 in Coddy's Recursion Challenges - Master The Recursive Thinking course.

challenge icon

Challenge

Easy

Write a function named findIndex that gets a string s and character c and returns the index of the first occurrence of c in s, if it does not exist, return -1.

Example:

  • test, s -> 2 Because character s appears first time at index 2

Try it yourself

#include <stdio.h>

int findIndex(char* s, char c) {
    // Write code here
    return -1;
}

All lessons in Recursion Challenges - Master The Recursive Thinking