blob: e2f2f5fdf07e8cf96b166954e609594da0f5225b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  | 
#include <stdio.h>
#define OUT 0
#define STAR 1
#define SLASH 2
/* this is a c programm to remove all comments from c programms */
// including "slash comments" 
/* and "star comments" */
// without the use of arrays
int 
main(void)
{
  char input, temp;
  int state;
  state = OUT;
  while ((input = getchar()) != EOF) {
    if (input == '/') {
       temp = input;
      if ((input = getchar()) == '*')
        state = STAR;
      else if (input == '/')
        state = SLASH;
      else 
        printf("%c", temp);
    }
    else if (input == '*' && state == STAR) {
      if ((input = getchar()) == '/') {
        state = OUT;
        if ((input = getchar()) != '\n')
          printf("%c", input);
        continue;
      }  
    }
    else if (input == '\n' && state == SLASH) {
      state = OUT;
      continue;
    }
    if (state == OUT)
      printf("%c", input);
  }
  return 0;
}
 
  |