Thread: Simple Eye-Candy program

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    14

    Angry Simple Eye-Candy program

    I'm going to pull my hair out!! I don't know what they hell is wrong with this simple program! I can't compile it, cuz it gives me the error: "Line 18, missing terminating ' character"

    Code:
    #include <stdio.h>
    
    #define POSITIVE '\'
    #define NEGATIVE 32
    #define COLUMN_WIDTH 40
    #define MAXLINES 100000
    
    main()
    {
        int c; /* character count */
        int l; /* line count */
        int p=0; /* positive value */
        
        for (l=1; l<=MAXLINES; ++l) {
            ++p;                    /* EQUATION */
            for (c=1; c!=p; ++c) {
                    putchar(NEGATIVE);
                    if (c > COLUMN_WIDTH) {
                                    c = COLUMN_WIDTH - c;
                    }
            }
            putchar(POSITIVE);
            putchar('\n');
        }
    }
    Line 18 is
    Code:
                    if (c > COLUMN_WIDTH) {
    I have no idea what's wrong, and it's driving me crazy.

    Anyone have ideas?

  2. #2
    .
    Join Date
    Nov 2003
    Posts
    307
    Code:
    #include <stdio.h>
    
    #define POSITIVE '\\'           // <--------- change
    #define NEGATIVE 32
    #define COLUMN_WIDTH 40
    #define MAXLINES 10
    
    main()
    {
        int c; /* character count */
        int l; /* line count */
        int p=0; /* positive value */
        
        for (l=1; l<=MAXLINES; ++l) {
            ++p;                    /* EQUATION */
            for (c=1; c!=p; ++c) {
                    putchar(NEGATIVE);
                    if (c > COLUMN_WIDTH) {
                                    c = COLUMN_WIDTH - c;
                    }
            }
            putchar(POSITIVE);
            putchar('\n');
        }
    }

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    14
    Awesome, thanks. Now the program isn't doing exactly what I wanted to.. but I'll try and figure that out.

    Thank you.

  4. #4
    Registered User
    Join Date
    Jun 2004
    Posts
    14
    Okay got it to work, here's my code:

    Code:
    #include <stdio.h>
    
    #define POSITIVE 'X'
    #define NEGATIVE 32
    #define COLUMN_WIDTH 20
    #define MAXLINES 100000
    #define EQUATION ++p
    
    main()
    {
        int c; /* character count */
        int l; /* line count */
        int p=0; /* positive value */
        
        for (l=1; l<=MAXLINES; ++l) {
            EQUATION;                    /* EQUATION */
            p %= COLUMN_WIDTH;
            for (c=0; c!=p; ++c) {
                    putchar(NEGATIVE);
            }
            putchar(POSITIVE);
            putchar('\n');
        }
    }
    The idea of this program is to experiment by defining different equations.

    Problem is, the thing zips by so freaking fast that you can't even see the pattern. Is there a way I can control the speed of it?

  5. #5
    .
    Join Date
    Nov 2003
    Posts
    307
    Try:
    Put in an fgets() call every 24 lines or so....

  6. #6
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463

  7. #7
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    I wouldn't advise using those sleeping functions because they are always runing and spent lots of CPU. Instead you could use the delay() function from the std libraries, although I think it's not ANSI C. This funtion uses the 0x15 interrupt to relinquish the CPU to other programs that might need it. If you're using VC++ you can use Sleep(), in windows.h, which does the same thing, but using the OS services.
    If you're using VC++, or Borland c++ builder, or another IDE insert breakpoints throughout your code and debug it.

    e.g.: if you do Sleep(500), your program stays idle for half second, and spents 0% CPU.

    //edit
    I had some porblems using the delay function in Windows XP: the time specified seems to be ignored, and the functions does nothing. Use Sleep instead: this works fine.

  8. #8
    ---
    Join Date
    May 2004
    Posts
    1,379
    int main()
    {
    ...
    return 0;
    }

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. [Help] Simple Array/Pointer Program
    By sandwater in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 02:42 PM
  3. simple silly program
    By verbity in forum C Programming
    Replies: 5
    Last Post: 12-19-2006, 06:06 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. I need help on a formula for this simple program.
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 01-28-2002, 10:01 PM