-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStoryProg.cpp
48 lines (43 loc) · 1.03 KB
/
StoryProg.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
#include<bits/stdc++.h>
using namespace std;
int count(string n, char ch) {
fstream file;
file.open(n.c_str(), ios::in);
if (!file) {
cout << "\nError reading file.";
return 1;
}
int counter = 0;
char data[80];
cout << "\nContents of file are: ";
while (file) {
file.getline(data, 80);
cout << data << endl;
if (data[0] == ch)
counter++;
}
return counter;
}
int counttotal(string n, char ch) {
ifstream fin;
fin.open(n.c_str());
int ct = 0;
while (!fin.eof()) {
fin >> ch;
ct++;
}
return ct;
}
int main() {
string name;
cout << "\nEnter the name of the file you want read: ";
cin >> name;
char ch;
cout << "\nEnter the character to check the first character with: ";
cin >> ch;
int c = count(name, ch);
cout << "\nThe number of line starting with " << ch << " is " << c;
int d = counttotal(name, ch);
cout << "\nThe total number of characters in file are: " << d;
return 0;
}