How to search for all occurrences of a character in given string with C

1 Answer

0 votes
#include <stdio.h>

int main() {

    char s[] = "c c++ java basic python c#";
    char ch = 'c';

    int i  = 0;
    while(s[i]) {
        if(s[i] == ch) {
            printf("found at index: %d\n", i);
        }
        i++;
    }

    return 0;
}




/*
run:

found at index: 0
found at index: 2
found at index: 15
found at index: 24

*/

 



answered Apr 14, 2022 by avibootz
...