home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!digex.com!jhurwitz
- From: jhurwitz@access.digex.com (j. hurwitz)
- Newsgroups: comp.lang.c
- Subject: More File read problems. Help I'm new and confused...
- Date: 15 Dec 1992 18:49:21 GMT
- Organization: Express Access Online Communications, Greenbelt, MD USA
- Lines: 51
- Sender: jhurwitz@access.digex.com
- Distribution: all
- Message-ID: <1gl9bhINN3f7@mirror.digex.com>
- NNTP-Posting-Host: access.digex.com
- Keywords: case file help duh problems pain in the ass
-
- Moving along on my syntax checking program, I have run into another dead end.
- When I run this code, It seems that my problem is that once the program finds
- a case and exits from the statement. it returns to the same point in the file
- that it left from. What could I do to get the program to read through the
- file, then when it reaches a case to test, throws a swicth and reads without
- checking for '{' or '}', then when it encounters matching case, continues on
- with the read after reading through that protion of the file and testing for
- '{}'s.
-
- -------------------------- cut here -------------------------
-
- //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, b=0, j=0;
- char ch;
-
- fptr = fopen("chkbrac.c","r");
-
- while ((ch =getc(fptr)) !=EOF)
- {
- j=0;
- switch (ch)
- {
- case '{': b++;
- break;
- case '}': b--;
- break;
- case '/*': while(j==0)
- { (ch=getc(fptr)); if (ch='*/') j=1; }
- break;
- case '\'': while(j==0)
- { (ch=getc(fptr)); if (ch='\'') j=1; }
- break;
- case '\"': while(j==0)
- { (ch=getc(fptr)); if (ch='\"') j=1; }
- break;
- } /* Junk to test program */
- } /* { {{{ '}' "}..."*/
- if (b==0)
- printf("\nBraces match !!!\n");
- else printf("\nBraces do not match\n");
- fclose(fptr);
- }
-
- --------------------- end --------------------------
-
- Thanx to all the people who replyed to my prevous message.
-