home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!spool.mu.edu!uwm.edu!csd4.csd.uwm.edu!eli
- From: eli@csd4.csd.uwm.edu (Elihu Lubkin)
- Newsgroups: comp.lang.c
- Subject: Re: Problems with Case statements HELP!
- Date: 15 Dec 1992 06:28:09 GMT
- Organization: University of Wisconsin - Milwaukee
- Lines: 53
- Distribution: usa
- Message-ID: <1gjttpINNobb@uwm.edu>
- References: <Bz18KA.MCv@access.digex.com>
- NNTP-Posting-Host: 129.89.7.4
-
- jhurwitz@access.digex.com (j. hurwitz) writes:
- :
- : Okay, I'm new to C so you'll have to forgive my lame question. Anyhoot,
- : I'm trying to write a program that will check for balanced braces in my
- : C source code.: But, when I try this:
- :
- : ============================== Begin Hack =========================
- : //programm to read a C source file and verify # of left to right braces
- :
- : #include <stdio.h>
- : int main(int argc, char *argv[])
- : {
- : FILE *fptr;
- : int l=0, r=0;
- : char ch;
- :
- : fptr = fopen("brachek3.c","r");
- : while ((ch =getc(fptr)) !=EOF)
- : {
- : switch (ch)
- : {
- : case '{': l++;
- break; <====otherwise { increments l & r; } only r.
- : case '}': r++; --Thelma
-
- : }
- : }
- : printf("\nl= %d r= %d", l, r);
- : if (l != r)
- : printf("\nBraces do not match\n");
- : else printf("\nBrace match !!!\n");
- : fclose(fptr);
- : }
- : ================================ End Hack ========================
- : I get an uneven number of braces at the end. I can't figure out what
- : I am doing wrong. I'm sure it is a minor oversight on my part. Any help
- : would be greatly appreciated
- :
- :
- :
- :
- : __/ / . + .
- : _/__/_/\
- : _/____/ \/ J. Hurwitz ,
- : . / / \/| . *
- : / / /|/ The MIDI master . o
- : /_____/ / |
- : //____/\\/ / Roaming Cyberspace "Space is the place"
- : / o \ ||/ .
- : | o o |// . -Sun Ra +
- : \o o// jhurwitz@access.digex.com
- : --^-- . *
- : + ' +
-