-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1-24.c
More file actions
51 lines (46 loc) · 1.08 KB
/
Copy path1-24.c
File metadata and controls
51 lines (46 loc) · 1.08 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
#include <stdio.h>
#define MAXLINE 10000
int agetline(char s[], int lim);
void check(char to[]);
int main()
{
int len;
char line[MAXLINE];
agetline(line, MAXLINE);
check(line);
return 0;
}
int agetline(char s[], int lim)
{
int c, i;
for (i=0; i<lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
s[i] = c;
if (c == '\n') {
s[i] = c;
++i;
}
s[i] = '\0';
return i;
}
void check(char to[])
{
int i;
int np, nb, nbr, nq, ns, nd;
/* () [] {} `` '' "" */
np = nb = nbr = nq = ns = nd = 0;
char from[MAXLINE];
for(i = 0; to[i] != '\0'; ++i) {
if (to[i] == '(') ++np;
if (to[i] == '[') ++nb;
if (to[i] == '{') ++nbr;
if (to[i] == ')') --np;
if (to[i] == ']') --nb;
if (to[i] == '}') --nbr;
if (to[i] == '`') if(nq == 1) --nq; else ++nq;
if (to[i] == 39) if(ns == 1) --ns; else ++ns;
if (to[i] == '"') if(nd == 1) --nd; else ++nd;
}
printf("if anything here equals zero, it is balanced\n");
printf("parathensis: %d brackets: %d braces: %d\n", np, nb, nbr);
printf("quotes: %d single: %d double: %d\n", nq, ns, nd);
}