Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

K&R exercise 1-23

Name: Anonymous 2010-06-06 19:43

/prog/ please help me.
I've been trying all evening to do this. I can't. I'm trying to do K&R exercise 1-23. Surely, I could look up the answer, but that isn't fun. Right now I'm trying to delete from '/*' and '*/' inclusive, ignoring whether it's between quotes or if it isn't. This is what I have so far:


#include <stdio.h>
main() {
    int c, i, t;
    while ((c = getchar()) != EOF) {
        if (c == '/' && (t = getchar()) == '*') {
            while (/*YOUR CONDITION HERE*/)
                ;
        } else if (c == '/'/* && t != '*'*/) {
            putchar(c);
            putchar(t);
        } else {
            putchar(c);
        }
    }
}

I have been thinking for a while what to put inside that while. I'm trying to put something that says "character is different from '*' and, if the previous condition is true, the next character is different from '/'". I tried with "c != '*' || (c = getchar()) != '/'" but that wouldn't work because whenever the first condition is true it loops infinitely, and the first condition will be true when it first checks it.

Name: Anonymous 2010-06-06 19:44

Use regular expressions, problem solved

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List