-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatic.cpp
More file actions
42 lines (36 loc) · 725 Bytes
/
static.cpp
File metadata and controls
42 lines (36 loc) · 725 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
// static.cpp -- using a static local variable
#include <iostream>
const int ArSize = 10;
void strcount (const char * str);
int main()
{
using namespace std;
char input[ArSize];
char next;
cout << "Enter a line: \n";
cin.get(input, ArSize);
while (cin) {
cin.get(next);
while (next != '\n') {
cin.get(next);
}
strcount(input);
cout << "Enter next line (empty line to quit): \n";
cin.get(input, ArSize);
}
cout << "Bye\n";
return 0;
}
void strcount(const char * str)
{
using namespace std;
static int total = 0;
int count = 0;
cout << "\"" << str << "\" contains ";
while (*str++) {
count++;
}
total += count;
cout << count << " characters\n";
cout << total << " characters total\n";
}