-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfileReading.cpp
More file actions
42 lines (35 loc) · 1.16 KB
/
fileReading.cpp
File metadata and controls
42 lines (35 loc) · 1.16 KB
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
//To read number of characters, numbers blank spaces etc. in a file
#include<bits/stdc++.h>
using namespace std;
int main() {
fstream fout;
int number_of_ints = 0, number_of_chars = 0, number_of_spaces = 0, special_chars = 0;
fout.open("sampleFile.txt", ios::in);
while(!fout.eof()){
char ch;
fout.get(ch);
if( ch >= 48 && ch <= 57){
if(fout.eof()) break;
number_of_ints++;
}
else if((ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122))
{
if(fout.eof()) break;
number_of_chars++;
}
else if(ch == 32) {
if(fout.eof()) break;
number_of_spaces++;
}
else {
if(fout.eof()) break;
special_chars++;
}
}
cout<<"Number of Digits present in the file: "<<number_of_ints<<endl;
cout<<"Number of Characters present in the file: "<<number_of_chars<<endl;
cout<<"Number of Spaces present in the file: "<<number_of_spaces<<endl;
cout<<"Number of Special Characters present in the file: "<<special_chars<<endl;
fout.close();
return 0;
}