lolamontes69

K+R Exercise1_23

Sep 5th, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int main()
  5. {
  6.     int c, lc;           /* lc = letter count */
  7.     unsigned char text[2000];
  8.     int CMT, NAC, EOC;   /* comment, not a comment, end of comment */
  9.  
  10.     lc = CMT = NAC = EOC = 0;
  11.    
  12.     while((c=getchar())!=EOF) {
  13.         if(c=='/' && CMT==0) CMT=1;
  14.         else if(c!='*' && CMT==1) {
  15.             CMT=0;
  16.             NAC=1;
  17.         }
  18.         else if(c=='*' && CMT==1) ++CMT;       /* CMT 2 means is a comment */
  19.         else if(c=='*' && CMT==2) ++CMT;
  20.         else if(c!='/' && CMT==3) --CMT;
  21.         else if(c=='/' && CMT==3) {
  22.             CMT=0;       /* CMT 0 means no comment */
  23.             EOC=1;       /* EOC 1 means don't print final '/' */
  24.         }
  25.         if(NAC==1) {
  26.             text[lc]='/';
  27.             NAC=0;
  28.             ++lc;
  29.         }
  30.         if(CMT==0 && EOC!=1) {
  31.             text[lc]=c;
  32.             ++lc;
  33.         }
  34.         EOC=0;
  35.     }
  36.     printf("\n-------------------------------------------------------\n");
  37.     for(c=0; c<lc; ++c)
  38.         printf("%c",text[c]);
  39.     printf("\n");
  40.     return(0);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment