-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrcmp.cpp
More file actions
46 lines (32 loc) · 893 Bytes
/
strcmp.cpp
File metadata and controls
46 lines (32 loc) · 893 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
43
44
45
46
//
// [mst] strcmp.cpp strcmp doodle
// simple string comparison run
//
// features, changelog:
// -2021.10.11: -initial draft
//
////////////////// LIBS
#include <iostream> // usage of console prints
using namespace std;
////////////////// DECL_IMPL
int strcmp_me (string str1, string str2){
if (str1.empty() || str2.empty()) {
return -1;
}
// iterate the substring
for (auto i = 0; i< str2.size(); i++) {
if (str1[i] != str2[i]) return -1;
}
return 1;
}
////////////////// DRIVER
int main()
{
cout << "[mst] strcmp doodle" << endl << endl;
string teststr = "hello there";
string substr = "hello";
std::cout << "comparing \'" << teststr << "\' and \'" << substr << "\' ..." << std::endl << std::endl;
std::cout << strcmp_me(teststr, substr) << std::endl;
//cin.get(); // pseudo-pause the console
return 0;
}