Making occurrence function (or) finding how many words are there by a character (or) how many times a given character occur

 #include<stdio.h>

int occurence(char st[], char c){

    char *ptr = st;

    int count=0;

    while(*ptr!='\0'){

        if (*ptr==c){

            count++;

        }

        ptr++;

    }

    return count;

}

int main(){

    char st[] = "sunil777";

    int count = occurence(st, '7');

    printf("Occurences = %d", count);

    return 0;

}

Comments

Popular posts from this blog

Snake game.c

Type declaration

Array with function