-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01.c
43 lines (42 loc) · 944 Bytes
/
01.c
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
/********************************************
*Advent of Code *
*Program Name: Day 1 *
*Programming Language: C *
*Author: José I. Escudero *
*E-mail: [email protected] *
*Date(DD/MM/YYYY): 06/12/2015 *
********************************************/
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
FILE* fp;
fp = fopen("01.txt", "r");
unsigned int c;
int level = 0;
char char1 = '(';
char char2 = ')';
int pos = 0, done = 0;
while((c = getc(fp)) != EOF)
{
if(((char)c) == char1)
{
level++;
pos++;
}
else if(((char)c) == char2)
{
level--;
pos++;
}
if(done != 1)
{
if(level == -1)
{
printf("POS = %i\n", pos);
done = 1;
}
}
}
printf("%i\n", level);
return 0;
}