Fun Examples

This is a discussion on Fun Examples within the C Programming forums, part of the General Programming Boards category; Well I want to start a thread that will unify (hehe) the board by asking everyone to "donate" a small ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    99

    Fun Examples

    Well I want to start a thread that will unify (hehe) the board by asking everyone to "donate" a small or large program that does absolutely nothing useful or something that could be a lifesaver. Yes I know that you can go to planetsourcecode.com and find every little goody that you want but this is to unify everyone (hehe). This will help people who like to look at code and see better ways of doing a certain task. So come one come all and share.

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    99
    Almost forgot to post mine.

    This is a simple filter type program for text files.
    Code:
    #include<ctype.h>
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    
    main(int argc, char *argv[]){
    FILE *fd,*out;
    int ch,c=0;
    if(argc<2){
        printf("Usage: Filter <filename><outfile.txt>\n");
        exit(1);
        }
    strcat(argv[1],".txt");
    strcat(argv[2],".txt");
    if((fd=fopen(argv[1],"r"))==NULL){
        printf("Could not open %s\n",argv[1]);
        exit(1);
        }
    if((out=fopen(argv[2],"w"))==NULL){
        printf("Could not open\n");
        exit(1);
        }
    while((ch=fgetc(fd))!=EOF){
        if(isalpha(ch))
        {
            if ((toupper(ch) >= 'A') && (toupper(ch) <= 'M'))
                ch = ch + 13;
            else
                ch = ch - 13;
        }
    fputc(ch,out);
    c++;
    }
    fclose(fd);
    fclose(out);
    printf("Filter complete with %d bytes read.\n",c);
    exit(0);
    }

  3. #3
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Here's 15 of them. I'm not saying they're the best, but, there, I donated. Some need a little work and quite a few are targeted for Windows. You can however modify them to be better in the portability area.
    Attached Files Attached Files
    The world is waiting. I must leave you now.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    ...does absolutely nothing useful... This will help people who like to look at code and see better ways of doing a certain task. So come one come all and share.
    Code:
    int main ( void )
    {
        return 0;
    }

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Rez
    Rez is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    82
    Code:
    int main(void)
    {
      for(;; ) {
        printf("Welcome to infinity!\n");
      }
    
      return 0;
    }

  6. #6
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638

    Smile areaprog.c

    I was going to submit this areaprog.c to the program challange at hdc. The challange was to calculate the area of circle square triangle and hexagon. The orignal poster did ask for 3d stuff but since circles squares and triangles and hexagons are 2d. Here it is.


    /* AreaProg.c by kryptkat */

    #include<stdio.h>
    #include<math.h>
    #define pi 3.14159265358979
    #define a 2.958
    int main()
    {

    double base;
    double d;
    double radius;
    double height;
    printf(" Radius of Circle\n");
    scanf("%f", &radius);
    printf(" Width\n");
    scanf("%f", &base);
    printf(" Height\n");
    scanf("%f", &height);

    d = (pow(base,2) * pi);
    printf(" Area of Circle is %f \n", d);
    d = pow(base,2);
    printf(" Area of Square is %f \n", d);
    d = (base * (height * 0.5) );
    printf(" Area of Triangle is %f \n", d);
    d = (pow(base,2) * a);
    printf(" Area of Hexagon is %f \n", d);
    return 0;
    }

  7. #7
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    This *could* be useful for outputting text in teletype mode I suppose, so you guys decide. :P

    Code:
    #include <stdio.h> 
    #include <time.h>
    
    void sleep( clock_t wait );
    
    int main(void)
    {
        int count;
        char message[] = "\nSome string to print.";
    		
        printf("For grins, let's see what this does.");
    	
        for(count = 0; message[count] != '\0'; count++)
        {
            putchar(message[count]);
            sleep( (clock_t)1 * CLOCKS_PER_SEC );
        }
        
         return 0;
    } 
    
    void sleep( clock_t wait )
    {
       clock_t goal;
       goal = wait + clock();
       while( goal > clock() )
          ;
    }

  8. #8
    Registered User
    Join Date
    Jan 2003
    Posts
    2
    just have a look at www.ioccc.org or
    http://www0.us.ioccc.org/years.html#1998_fanf
    if you are searching for amazing code snippets

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows - how to get started... examples don't help
    By nonoob in forum Windows Programming
    Replies: 6
    Last Post: 09-26-2008, 05:45 AM
  2. Auto Calling Derived Fun
    By Arlenik in forum C++ Programming
    Replies: 27
    Last Post: 06-02-2008, 11:17 AM
  3. Fun Learning a New Language
    By UnregdRegd in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-30-2003, 10:03 PM
  4. Treeview examples.
    By Sebastiani in forum Windows Programming
    Replies: 0
    Last Post: 09-21-2003, 12:16 PM

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