Thread: fill array with odd numbers

  1. #16
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Hehehe... I see both of us enjoy IOCCC:

    Compile with a simple 'gcc -o http http.c'

    Code:
          #include/*           micro HTTP server           */<stdio.h>
         #include/*           usage: ./http [port]          */<stdlib.h>
        #include/*                                           */<string.h>
         #include/*   the default port is 8080, files are   */<unistd.h>
          #include/*    read from the current directory    */<netdb.h>
    
    
                      int main(int n,char**
                      V){int t=SOCK_STREAM,
                      N=SO_REUSEADDR,i=1,c=
                             htons(n
      >1?atoi       (V[1]):  101*80)  ;struct sockaddr_in s
      ={(0)};       void*f=  &s;char  *m,b[1036];s.sin_port
      =c;for(       N=!((t=  socket(  s.sin_family=AF_INET,
      #define       http(c)  setsock         ##opt(\
      t,SOL_S       ##OCKET  ,N,&i,c         (i)),bi  ##nd(t,f,c(s))<0)||
      t,0))<0       ||(http  (sizeof         )listen  (t,5))<<10;N&&(0)<=(c
      =accept(t,0,0));close  (c)){b[         n=recv(  c,b,N,0),0>n?0:n]=0;n
      =!memcmp(b,"GET /",5)  <<6;for         (i=4;n^  '?'&&n<       127&&n>
      32;)n=b[++i];f=0;m=n?  strcpy(         b+i,b[i  -1]-'/'       ?"":"i"
      "ndex."       "html")  ,printf         ("%s\n"  ,(5+b))       ,strstr
      (b,"/."       )||0==(  f=fopen         (&b[5],  "rb"))?"404 Not Foun"
      "d":"2"       "00 OK"                  :"501 "  "Not Implemented";for
      ((send)       ((c),b,                  sprintf  (b, "HTTP/1.1 %s\n"
      "\r\n%"       "s",m,f                  ?"":m),  0);f&&!
      ((send)       (c,b+0,                  fread(b  ,1,N,f)
                                                      ,0)-N&& 
                                                      fclose(
                                                      f)|404*
                                                      N););}

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Y'all just showing off now
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #18
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > But I fail to see why pointer arithmetic and indirection, plus pos-increment are "obfuscation".
    For the OP, I'm pretty damn sure that what you posted would count as obfuscated.

    As for all the other copy/pasta from ioccc, merry ..... christmas.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 08-28-2021, 10:47 AM
  2. Fill the array help
    By IMMORTALX in forum C Programming
    Replies: 7
    Last Post: 09-09-2011, 03:34 AM
  3. fill an array with numbers from 1 to 10
    By bos1234 in forum C Programming
    Replies: 2
    Last Post: 01-26-2011, 12:38 PM
  4. Replies: 1
    Last Post: 11-02-2009, 06:45 AM
  5. Replies: 2
    Last Post: 04-27-2008, 03:39 AM

Tags for this Thread