Skip to content

Instantly share code, notes, and snippets.

@cannapages
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cannapages/11298577 to your computer and use it in GitHub Desktop.
Save cannapages/11298577 to your computer and use it in GitHub Desktop.
Bjarne Stroustrup Exerpt
#include <iostream>
using namespace std;
int count_x(char* p, char x) {
if (p==nullptr) return 0;
int count = 0;
for (; *p!=0; ++p)
if(*p==x)
++count;
return count;
}
int main() {
char foo[12] = "Hello World";
cout << "There are " << count_x(foo, 'l') << " l's in " << foo << "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment