rendered paste body#include <stdio.h>
void print_depth(int depth);
int main(int argc, char *argv[])
{
FILE *in_file;
char input;
int depth=0;
if (argc != 2) {
printf("%s <file to inspect>\n",argv[0]);
exit(1);
}
if ((in_file = fopen(argv[1],"r")) == NULL) {
printf("Error opening file!\n");
exit(1);
}
while ((input = fgetc(in_file)) != EOF) {
if (input == '{') {
++depth;
print_depth(depth);
}
if (input == '}') {
print_depth(depth);
--depth;
}
}
printf("Final depth: %d\n",depth);
if (depth == 0)
printf("No problems with brackets!\n");
return 0;
}
void print_depth(int depth)
{
int x;
for (x = 0; x < 5*depth; ++x)
printf("*");
if (depth > 0)
printf("\n");
}