forked from tanus786/CP-Codes-HackOctober-Fest-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile-handling.cpp
More file actions
42 lines (38 loc) · 866 Bytes
/
file-handling.cpp
File metadata and controls
42 lines (38 loc) · 866 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
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
int main()
{
ifstream write_f;
write_f.open("file.txt");
char str;
int c_num = 0;
int c_words = 0;
int c_lines = 0;
int c_char = 0;
while (!write_f.eof())
{
write_f.get(str);
if (str== ' ')
{
c_words++;
}
else if ((str >= 65 && str <= 90) || (str >= 97 && str <= 122))
{
c_char++;
}
else if (str >= '0' && str <= '9')
{
c_num++;
}else if(str = '\n'){
c_lines++;
}
}
cout << "Total characters : " << c_char << endl;
cout << "Total digits : " << c_num << endl;
cout << "Total words : " << c_words + 1 << endl;
cout << "Total lines : " << c_lines << endl;
write_f.close();
return 0;
}