summaryrefslogtreecommitdiffstats
path: root/1/23.c
diff options
context:
space:
mode:
Diffstat (limited to '1/23.c')
-rw-r--r--1/23.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/1/23.c b/1/23.c
new file mode 100644
index 0000000..fdb4a5b
--- /dev/null
+++ b/1/23.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+
+#define NONE 0
+#define SINGLLC 1
+#define MULTILC 2
+#define MAXLEN 1000
+
+/* removes comments from a c program */
+int main(int argc, char *argv[]) {
+ int prev, curr, i, comment;
+ char s[MAXLEN];
+
+ i = prev = 0;
+ comment = NONE;
+
+ while (i < MAXLEN - 1 && (curr = getchar()) != EOF) {
+ if (!comment) {
+ if (curr == '/' && prev == '/') {
+ comment = SINGLLC;
+ i--;
+ } else if (curr == '*' && prev == '/') {
+ comment = MULTILC;
+ i--;
+ } else {
+ s[i++] = curr;
+ }
+ } else if ((comment == SINGLLC && curr == '\n') ||
+ (comment == MULTILC && curr == '/' && prev == '*')) {
+ comment = NONE;
+ }
+
+ prev = curr;
+ }
+
+ s[i] = 0;
+
+ printf("c code: \n");
+ printf("%s\n", s);
+
+ return 0;
+} \ No newline at end of file