-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathex04.cpp
52 lines (46 loc) · 944 Bytes
/
ex04.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
#include <iostream>
using namespace std;
#include <cstring>
struct stringy {
char * str;
int ct;
};
void set(stringy &beany, char * test);
void show(const stringy &beany, int times = 1);
void show(const char * str, int times = 1);
int main()
{
stringy beany;
char testing[] = "Reality isn't what it used to be.";
set(beany, testing);
show(beany);
show(beany, 2);
testing[0] = 'D';
testing[1] = 'u';
show(testing);
show(testing, 3);
show("Done!");
return 0;
}
void set(stringy &beany, char * test)
{
int length = strlen(test);
char * str = new char[length + 1];
strcpy(str, test);
beany.str = str;
beany.ct = length;
}
void show(const stringy &beany, int times)
{
for (int i = 0; i < times; i++)
{
std::cout << beany.str;
}
}
void show(const char * str, int times)
{
for (int i = 0; i < times; i++)
{
std::cout << str;
}
}