I'm sure I'll soon feel stupid to ask this question. I'm trying to use printf() to see how far along my code got. But it wasn't printing anything even when I added printf to the first line in main(). And when I used debug50, it went to and passed that line but didn't print anything.

int main(int argc, char *argv[])
    // This line isn't printing anything.
    printf("start main");

    // Check for correct number of args
    if (argc != 2 && argc != 3)
        printf("Usage: speller [dictionary] text\n");
        return 1;
    // Here skips the codes we were given for simplicity of the question, but I didn't change anything

Please help.


This will (hopefully) explain this specific problem in main and perhaps the overriding problem. The output buffer is not "flushed" until a new line (or explicit flush). The answer provided here explains it. If the added debugging printfs are "not executing" it could be for the same reason, since the first "\n" that is encountered would likely be after "MISSPELLED WORDS". Changing this printf("start main"); to this printf("start main\n"); will change the result.

  • Thank you! This solved the problem. So without '\n', the program was waiting for the next line, or the rest of the lines if none of them have '\n', to print to the terminal (flush). Is that correct? – CTK2019 Mar 11 '20 at 4:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .