Last active
August 29, 2015 14:00
-
-
Save cannapages/11298577 to your computer and use it in GitHub Desktop.
Bjarne Stroustrup Exerpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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