home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18419 < prev    next >
Encoding:
Text File  |  1992-12-15  |  2.0 KB  |  65 lines

  1. Path: sparky!uunet!digex.com!jhurwitz
  2. From: jhurwitz@access.digex.com (j. hurwitz)
  3. Newsgroups: comp.lang.c
  4. Subject: More File read problems. Help I'm new and confused...
  5. Date: 15 Dec 1992 18:49:21 GMT
  6. Organization: Express Access Online Communications, Greenbelt, MD USA
  7. Lines: 51
  8. Sender: jhurwitz@access.digex.com
  9. Distribution: all
  10. Message-ID: <1gl9bhINN3f7@mirror.digex.com>
  11. NNTP-Posting-Host: access.digex.com
  12. Keywords: case file help duh problems pain in the ass
  13.  
  14. Moving along on my syntax checking program, I have run into another dead end.
  15. When I run this code, It seems that my problem is that once the program finds
  16. a case and exits from the statement. it returns to the same point in the file
  17. that it left from. What could I do to get the program to read through the 
  18. file, then when it reaches a case to test, throws a swicth and reads without
  19. checking for '{' or '}', then when it encounters matching case, continues on 
  20. with the read after reading through that protion of the file and testing for 
  21. '{}'s.
  22.  
  23. -------------------------- cut here -------------------------
  24.  
  25. //programm to read a C source file and verify # of left to right braces
  26. #include <stdio.h>
  27.  
  28. int main(int argc, char *argv[])
  29. {
  30.    FILE *fptr;
  31.    int l=0, r=0, b=0, j=0;
  32.    char ch;
  33.  
  34.    fptr  = fopen("chkbrac.c","r");
  35.  
  36.    while ((ch =getc(fptr)) !=EOF)
  37.      {
  38.      j=0;
  39.      switch (ch)
  40.        {
  41.        case '{': b++;
  42.                     break;
  43.        case '}': b--; 
  44.                     break;
  45.        case '/*': while(j==0)
  46.                 { (ch=getc(fptr)); if (ch='*/') j=1; }
  47.                 break;
  48.        case '\'': while(j==0)
  49.                 { (ch=getc(fptr)); if (ch='\'') j=1; }
  50.                 break;
  51.        case '\"': while(j==0)
  52.                 { (ch=getc(fptr)); if (ch='\"') j=1; }
  53.                 break;
  54.        }                     /* Junk to test program */
  55.      }                       /* { {{{ '}' "}..."*/
  56.    if (b==0)
  57.     printf("\nBraces match !!!\n");
  58.    else printf("\nBraces do not match\n");
  59.    fclose(fptr);
  60. }
  61.  
  62. --------------------- end --------------------------
  63.  
  64. Thanx to all the people who replyed to my prevous message. 
  65.