-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8.cpp
37 lines (34 loc) · 862 Bytes
/
8.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
/*
8. Write a C/C++ program that reads text from a file, then count and prints the number of character exist in the inputted text file.
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fl(i, a, n) for (int i = a; i < n; i++)
#define pb push_back
#define all(p) p.begin(), p.end()
#define rall(v) v.rbegin(), v.rend()
#define vi vector<int>
#define vvi vector<vi>
#define imr_an ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
void solve(){
ifstream file("input.txt");
if (!file) {
cout << "Unable to open file"<< endl;
return;
}
string s;
char ch;
int charCount = 0;
while(getline(file,s))fl(i,0,s.size())if(s[i]!=' ')charCount++;
file.close();
cout<<charCount<<endl;
}
int main()
{
imr_an
int t=1;
// cin>>t;
while(t--)solve();
return 0;
}