-
Notifications
You must be signed in to change notification settings - Fork 2
/
finder.cpp
56 lines (53 loc) · 1.02 KB
/
finder.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
49
50
51
52
53
54
55
56
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int getUnused(int arr[])
{
for(int a = 0; a < 100; a++)
{
if(arr[a] == -1) return a;
}
}
int main()
{
string name;
cout<<"enter name of file: "; getline(cin, name);
cin;
ifstream file;
file.open(name.c_str());
if(!file.is_open()) {
cout<<"not opened";
return 0;
}
string line;
int linenumber = 1, openBrace[100], ezpz = 0, meh = -1, lastIn[100];
for(int zz = 0; zz < 100; zz++) { openBrace[zz] = -1; lastIn[zz] = -1;}
while(getline(file, line))
{
for(int i = 0, len = line.length(); i < len; i++)
{
if(line[i] == '{')
{
meh = getUnused(openBrace);
openBrace[meh] = linenumber;
lastIn[ezpz] = meh;
ezpz++;
}
if(line[i] == '}')
{
ezpz--;
openBrace[lastIn[ezpz]] = -1;
}
}
linenumber++;
}
int countt = 0;
for(int b = 0; b < 100; b++){
if(openBrace[b] != -1){
countt++;
cout<<"There is an unclosed brace at line number: " << openBrace[b] <<endl;
}
}
if(countt == 0) cout<<"No Miss";
}