forked from reachanihere/Data-Structures-and-Algorithms
/
Strings.cpp
65 lines (42 loc) · 929 Bytes
/
Strings.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
using namespace std;
#include <cstring>
void printAllPrefixes(char input[]) {
// i represents end index of my prefix
for(int i = 0; input[i] != '\0'; i++) {
// j represents start index of my prefix
for(int j = 0; j <= i; j++) {
cout << input[j];
}
cout << endl;
}
}
int main() {
char input1[100] = "abcd";
printAllPrefixes(input1);
/*
char input2[100] = "xy";
cout << "Before copying : ";
cout << "Input 1 : " << input1 << endl;
cout << "Input 2 : " << input2 << endl;
//strcpy(input1, "hello");
strncpy(input1, input2, 4);
cout << "After copying : ";
cout << "Input 1 : " << input1 << endl;
cout << "Input 2 : " << input2 << endl;
*/
//cin >> input1;
//cin >> input2;
/*
if(strcmp(input1, input2) == 0) {
cout << "true" << endl;
}
else {
cout << "false" << endl;
}
*/
/*
int len = strlen(input);
cout << "Length : " << len << endl;
*/
}