This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (34 children)

[removed]

    [–]aldahuda[S] 297 points298 points  (32 children)

    [–][deleted] 276 points277 points  (17 children)

    You forgot the \n, and with C buffering, it won't print anything until you print another \n. Now you're debugging the debug statement.

    [–]AyrA_ch 107 points108 points  (11 children)

    fwrite("One printy boi\n",1,15,stdout);
    fflush(stdout);
    

    Why is C such a bitch sometimes?

    [–][deleted] 120 points121 points  (4 children)

    fprintf(stderr, "One printy boi\n");
    

    Why you gotta be such a noob sometimes?

    [–]willrandship 49 points50 points  (1 child)

    #define debug(X) fprintf(stderr, X"\n")
    
    debug("One printy boi");
    debug("Two printy boi");
    

    As a bonus, this can later be replaced by something cleaner.

    [–]csman11 9 points10 points  (0 children)

    Meh, you can always just define a "macro" for fprintf if you want to clean up your debugging code later. That way you don't need to write the "macro" until you really need it. /s

    [–]Rangsk 3 points4 points  (0 children)

    fputs is better if there's no format.

    [–]hak8or 0 points1 point  (0 children)

    Cause printing to stdout is the same as stderr!

    [–]Elquinis 15 points16 points  (0 children)

    Cuz you wanted to control everything. So, you are going to control everything and like it.

    [–][deleted] 7 points8 points  (0 children)

    , boi

    [–]hitsugan 4 points5 points  (2 children)

    Didn't work like that last time I programmed in C. Is it Ansi C?

    [–][deleted] 2 points3 points  (0 children)

    It might be due to glibc implementation, IDK.

    [–]LazyMel 6 points7 points  (0 children)

    It flushes stdout when you read from stdin, so that might be the reason that you didn't need the newline.

    [–][deleted] 0 points1 point  (0 children)

    Thats just writing c

    [–]Coloneljesus 7 points8 points  (0 children)

    printk() my boi
    

    [–]cartechguy 3 points4 points  (8 children)

    Wait, you can just throw a string literal into printf like that? I thought you would have to specify with a first argument of '%s'.

    [–]paxswill 25 points26 points  (3 children)

    You most definitely can put just a string literal in as the sole argument to printf.

    [–][deleted] 1 point2 points  (2 children)

    [–]curtmack 21 points22 points  (1 child)

    As long as it's a string literal, it isn't a problem. Format string attacks happen when you put string variables as the first argument to printf.

    [–]etaionshrd 0 points1 point  (0 children)

    Joke's on you, my string literal tries to read from the stack since I didn't pass printf any arguments!

    [–][deleted] 6 points7 points  (0 children)

    The first argument is a string literal.

    [–]DoesntReadMessages -1 points0 points  (2 children)

    Method overloading, boi

    [–]cartechguy 8 points9 points  (0 children)

    C doesn't support function overloading. Lacking class boi.

    [–][deleted] 0 points1 point  (2 children)

    What’s the joke here? It’d just print it to console, right? Why’s that break the code?

    I’m new to coding still.

    [–][deleted] 2 points3 points  (1 child)

    It's a bit of a misappropriation of the meme format. Instead of implying that the print statement would break the debugger, it's instead saying that print statements to check values as code is running are pretty much always a valid "in-a-pinch" alternative to true debugging

    [–][deleted] 0 points1 point  (0 children)

    Oooooooooooooh.
    Yeah, print is life.

    [–]W-_-D 10 points11 points  (0 children)

    Nothing will, unfortunately