Created
May 9, 2017 21:58
-
-
Save rjwebb/c3b406938236e1be34889564c106f515 to your computer and use it in GitHub Desktop.
A little C program (script!) that checks if the braces are closed on stdin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(void) | |
{ | |
FILE *fp; | |
fp = stdin; | |
int depth = 0; | |
int c; | |
while (!feof(fp)) { | |
c = fgetc(fp); | |
if (c == '{') { | |
depth++; | |
} else if (c == '}') { | |
depth--; | |
} | |
} | |
if (depth == 0) { | |
printf("All braces have been closed!\n"); | |
} else if (depth > 1) { | |
printf("Some braces have been left open! (%c)\n", depth); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment