Hello, I am trying to write a program that counts how many times a letter occurs in a string. I know there's easy ways to do it, but I want to use the strchr function to have a search key. I wrote this and for some reason, nothing even happens when I run it! No errors or nothing so I'm not sure what the problem could be! Any help is appreciated
#include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[])
{
const char * random_text = "Once there was this really old man who tranformed into dust. The end!";
int counter = 0;
int searchKey = 'd';
char * strPtr = strchr(random_text, searchKey);
do {
if(strPtr != NULL)
counter++;
strPtr = strchr(random_text+1, searchKey);
} while (strPtr != NULL);
printf("%s\n%s\n\n%s%c%s%d%s", "The text:", random_text, "The occurence of ",
searchKey, " happened ", counter, " times.\n");
return 0;
}