-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquirks.cpp
More file actions
42 lines (31 loc) · 803 Bytes
/
quirks.cpp
File metadata and controls
42 lines (31 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <windows.h>
using namespace std;
#define REPEAT(i,a,b) for (int i = a; i <= b; i++)
DWORD StrOcc(char *src, char ch)
{//Count occurrences of a char.
DWORD i=0;
if (!src) return 0;
while (*src)
if (*src++==ch) //checks if character is equal if so increment.
i++;
return i;
}
size_t StrOcc(const char *src, char ch) {
size_t count = 0;
if (src == nullptr) return 0;
while (*src) {
if (*src++ == ch) count++;
}
return count;
}
int main(int argc, char* argv[]){
char* hiss = "hiss";
char s = 's';
int i = StrOcc(hiss,s);
cout << s << " occurs in " << hiss << " " << i << " times";
REPEAT(i, 1, 10) {
cout << i << " is a and I = " << i << endl;
}
return 0;
}