I have the string str
char *str = "100.10b.100.100";
I want to count the occurrences of '.'
in str
, preferably a one-liner. (If possible no loops)
My approach would be the standard strchr
:
int i = 0;
char *pch=strchr(str,'.');
while (pch!=NULL) {
i++;
pch=strchr(pch+1,'.');
}
See Question&Answers more detail:os