diff options
| author | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-11-22 20:06:27 +0800 |
|---|---|---|
| committer | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-11-22 20:06:27 +0800 |
| commit | ce26f83b5871a2459e3d607be007cdb6e86b84e7 (patch) | |
| tree | 0c17faf1807c151d56c7dcc4c414eeda4e57d288 /1 | |
| parent | 6bdc8e7a1102b0536d6bdd7ae4d83b1f33b5784c (diff) | |
| download | k&r-exercises-ce26f83b5871a2459e3d607be007cdb6e86b84e7.tar.gz | |
1.23
Diffstat (limited to '1')
| -rw-r--r-- | 1/23.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -3,22 +3,26 @@ #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; + int prev, curr, i, comment, inquote; char s[MAXLEN]; - i = prev = 0; + inquote = i = prev = 0; comment = NONE; while (i < MAXLEN - 1 && (curr = getchar()) != EOF) { if (!comment) { - if (curr == '/' && prev == '/') { + if (curr == '"' && prev != '\\') { + s[i++] = curr; + inquote = !inquote; + } else if (!inquote && curr == '/' && prev == '/') { comment = SINGLLC; i--; - } else if (curr == '*' && prev == '/') { + } else if (!inquote && curr == '*' && prev == '/') { comment = MULTILC; i--; } else { |
