aboutsummaryrefslogtreecommitdiff
path: root/1.23.c
diff options
context:
space:
mode:
authorsinanmohd <pcmsinan@gmail.com>2022-06-04 12:11:15 +0530
committersinanmohd <pcmsinan@gmail.com>2022-06-04 12:11:15 +0530
commitc24973af02bc33f2f5f25d37e22ca91da5de3c47 (patch)
tree460a005b6a3a9a967bd881bc2bf01e0becbe33cc /1.23.c
inital commit
Diffstat (limited to '1.23.c')
-rw-r--r--1.23.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/1.23.c b/1.23.c
new file mode 100644
index 0000000..e2f2f5f
--- /dev/null
+++ b/1.23.c
@@ -0,0 +1,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;
+}