Rolling Snowball program

This is a discussion on Rolling Snowball program within the General Discussions forums, part of the Community Boards category; In this thread, we first start with a simple "hello, world" program and then each person that replies adds 1-5 ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    103

    Rolling Snowball program

    In this thread, we first start with a simple "hello, world" program and then each person that replies adds 1-5 lines to program. No more than five lines may be added at a time. NO double posting. Deleting a line is considered adding a line. Two functions or two declarations cannot be on the same line. Try to keep the code have very few dependencies as possible (aside from the standard C library). No windows includes. Linux/UNIX includes are okay, but stay away from them as far as possible. Make sure it compiles correctly. Lets see how far this goes

    Oh yeah, ANSI C of course.

    Code:
    #include <stdio.h>
    
    int main (void) {
       printf("Hello, world!\n");
       return 0;
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I assume that it's supposed to always compile at every stage.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    int main (void) {
       srand(time(NULL));
       int z = rand()%12;
       printf("Hello, world!\n");
       return 0;
    }
    We'll see whether somebody takes the direction I have in mind.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    103
    Yup. It is.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <sys/types.h>
    int main (void) {
       struct time_t alloc;
       srand(time(&alloc));
       int z = rand()%12;
       printf("Hello, world!\n");
       return 0;
    }
    Probably not what you were thinking...

  4. #4
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,425
    that wont compile for me as "storage size of alloc not known' GNU Gcc compiler in codeblocks

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,725
    Change struct time_t to time_t. Note that contrary to the rules, <sys/types.h> is not part of the C standard library. (EDIT: okay, so the rules do allow for "Linux/UNIX includes", but considering that this header is not needed here...)

    Anyway, I'm moving this game to General Discussions.

    Might as well fix it:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void) {
       int z = rand()%12;
       printf("Not so random, huh: %d\n", z);
       return 0;
    }
    Last edited by laserlight; 03-31-2010 at 05:42 AM.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,425

    lines added = 6 but come on, curly braces!

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int GetTheBallRolling(int z)
    {
        return z;
    }
    
    int main(void) {
       int z = rand()%12;
       int x = 0;
    
       printf("Not so random, huh: %d\n", z);
    
       x = GetTheBallRolling(z);
    
    
       return 0;
    }

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int GetTheBallRolling(int z)
    {
        if (z <= 1)
            return z;
        if (z%2)
            return GetTheBallRolling(3*z+1);
        return GetTheBallRolling(z/2);
    }
    
    int main(void) {
       int z = rand()%12;
       int x = 0;
    
       printf("Not so random, huh: %d\n", z);
    
       x = GetTheBallRolling(z);
    
    
       return 0;
    }

  8. #8
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    void marbles(int *n) {
    	*n--;
    	printf("\t\tx_%d\n",*n);
    }
    
    int GetTheBallRolling(int z) {
    	printf("%d\n",z);
        if (z <= 1) return z;
    	z++;
        if (z%2) return GetTheBallRolling(3*z+1);
        return GetTheBallRolling(z/2);
    }
    
    int main(void) {
       int z = rand()%12;
       int x = 0;
    
       printf("Not so random, huh: %d\n", z);
    
       x = GetTheBallRolling(z);
    	if (z) marbles(&z);
    
       return 0;
    }
    Last edited by MK27; 03-31-2010 at 07:43 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  9. #9
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    That was so much fun I'm going twice:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    void mirror(int x) {
    	unsigned u;
    	memcpy(&u,&x,sizeof(int));
    	printf("%u\n",u);
    	if (u) mirror(u/2);
    }
    
    void marbles(int *n) {
    	*n--;
    	printf("\t\tx_%d\n",*n);
    	mirror(--(*n));
    }
    
    int GetTheBallRolling(int z) {
    	printf("%d\n",z);
        if (z <= 1) return z;
    	z++;
        if (z%2) return GetTheBallRolling(3*z+1);
        return GetTheBallRolling(z/2);
    }
    
    int main(void) {
       int z = rand()%12;
       int x = 0;
    
       printf("Not so random, huh: %d\n", z);
    
       x = GetTheBallRolling(z);
    	if (z) marbles(&z);
    
    
       return 0;
    }
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  10. #10
    Registered User
    Join Date
    Jan 2009
    Posts
    103
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    void mirror(int x) {
    	unsigned u;
    	memcpy(&u,&x,sizeof(int));
    	printf("%u\n",u);
    	if (u) mirror(u/2);
    }
    
    void marbles(int *n) {
    	*n--;
    	printf("\t\tx_%d\n",*n);
    	mirror(--(*n));
    }
    
    int GetTheBallRolling(int z) {
    	printf("%d\n",z);
        if (z <= 1) return z;
    	z++;
        if (z%2) return GetTheBallRolling(3*z+1);
        return GetTheBallRolling(z/2);
    }
    
    int main(void) {
       int z = rand()%12;
       int x = 0;
    
       printf("Not so random, huh: %d\n", z);
    
       x = GetTheBallRolling(z);
    	if (z) marbles(&z);
       printf("Come on people, more code!\n");
    
       return 0;
    }

  11. #11
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    If the point here is to try and create one huge thread of code I doubt it will work or stay open for very long. I see some serious language debates in its future.

  12. #12
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by Bubba View Post
    If the point here is to try and create one huge thread of code I doubt it will work or stay open for very long. I see some serious language debates in its future.
    I agree, it's not very interesting. Because it's not being worked towards a certain goal; one person codes something useless and another does something else useless.

    I propose we do this again, but we work towards a certain goal. Make up an interesting application we could make (I suggest a Brain........ interpreter/compiler), and build that. The fun bit is that others will think differently but have to work in the previous person's tracks.

  13. #13
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,703
    We could all try to draw instead? Even if we code toward a goal together, that's a project and less a game.

  14. #14
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    I thought it was cool because the code was for animating a snowball rolling down a hill, turns out it's not

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  3. rolling dice program
    By sunny2005 in forum C Programming
    Replies: 20
    Last Post: 03-21-2005, 03:45 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21