-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode_indent.cpp
56 lines (52 loc) · 1.1 KB
/
code_indent.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<bits/stdc++.h>
using namespace std;
int main()
{
int i,count=0;
char ch;
FILE *fp;
fp=fopen("f3.txt","r");
if(fp==NULL)
{
cout<<"file cannot open";
exit(0);
}
ch=fgetc(fp);
while(!feof(fp))
{
if(ch=='>')
{
cout<<ch;
cout<<"\n";
}
else if(ch==';')
{
cout<<ch;
cout<<"\n";
for(i=0;i<2*count;i++)
cout<<" ";
}
else if(ch=='{')
{
cout<<"\n";
for(i=0;i<2*count;i++)
cout<<" ";
cout<<ch;
cout<<"\n";
cout<<" ";
count++;
}
else if(ch=='}')
{
count--;
cout<<"\n";
for(i=0;i<2*count;i++)
cout<<" ";
cout<<ch;
}
else
cout<<ch;
ch=fgetc(fp);
}
fclose(fp);
}