-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculate KLOC.cpp
More file actions
73 lines (55 loc) · 1.33 KB
/
Calculate KLOC.cpp
File metadata and controls
73 lines (55 loc) · 1.33 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <bits/stdc++.h>
#include <stack>
/* fstream header file for ifstream, ofstream,
fstream classes */
#include <fstream>
using namespace std;
// Driver Code
int main()
{
//vector<string> vs;
int comments = 0, comma = 0, space = 0, lines = 0;
int semicolon = 0, blankLines = 0;
// Creation of fstream class object
fstream fio;
string line;
fio.open("inp.txt", ios::app | ios::out | ios::in);
// Execute a loop untill EOF (End of File)
// point read pointer at beginning of file
fio.seekg(0, ios::beg);
while (fio)
{
//Read a Line from File
getline(fio, line);
int flag = 0;
for(int i = 0; i < (int)line.length()-1; i++)
{
if(line[i] == '/' && line[i+1] == '/')
comments++;
if(line[i] == '/' && line[i+1] == '*')
comments++;
if(line[i] == ' ')
space++;
if(line[i] == ',')
comma++;
if(line[i] == ';' || (i == (int)line.length() - 2 && line[i+1] == ';'))
semicolon++;
if(line[i] != ' ')
flag = 1;
}
if(flag==1)
lines++;
else
blankLines++;
}
// Close the file
fio.close();
cout<<"Lines :"<<lines<<endl;
cout<<"Blank Lines :"<<blankLines<<endl;
cout<<"Spaces :"<<space<<endl;
cout<<"Semicolons :"<<semicolon<<endl;
cout<<"Comments :"<<comments<<endl;
cout<<"Commas :"<<comma<<endl;
return 0;
}