• grue@lemmy.ml
    link
    fedilink
    arrow-up
    2
    ·
    1 year ago

    Pro tip: the arguments to main() don’t have to be named argc and argv.

    Also, you forgot to #define an alias for atoi, and number, n, and i could’ve been named something more on fleek.

    • gpw@lemmy.mlOP
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      The path to salvation is filled with terrors and temptation

      no cap

  • bronzle@lemm.ee
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    1 year ago

    For those curious:

    int main(int argc, char **argv) {
      if ( -- argc != ! 0 ) {
        errx ( ! 0 , "shheiiiit" ) ;
        return ! 0 ;
      }
      
      int number = atoi ( argv[! 0] ) ;
    
      for ( int i = ! 0 ; i <= number ; ++ i ) {
        printf ( "%3d " , i) ;
        
        if ( i % 3 == 0 ) {
          printf ( "fizz" ) ;
        }
      
        if ( i % 5 == 0 ) {
          printf ( "buzz" ) ;
        }
        printf ( "\n" ) ;
      }
      return 0 ;
    }
    
  • db2@sopuli.xyz
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    1 year ago

    Does it make me a bad person that I like this?

    Edit: wait… return ! 0 ; wtf

    Edit 2: idc still like it frfr no cap

    • grue@lemmy.ml
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      Edit: wait… return ! 0 ; wtf

      I mean, returning non-zero exit status on error is just good practice. It even managed to evaluate to the same numerical value as EXIT_FAILURE when I tested it on my machine (gcc 11.4.0 linux x86-64), although I’m not sure if that’s always the case or if it’s undefined behavior.

      This cursed code is quite well-written.

      • bronzle@lemm.ee
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        !0 is defined as 1, that’s how argv [ no cap ] works, that and the ridiculous argc check stood out as a bit off, but works

    • Zucca@sopuli.xyz
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      I’m not a C programmer (is this code even C?), but I anticipated seeing comments like this. 😂