-
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?
-
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');
}
}
-
Awesome, thanks. Now the program isn't doing exactly what I wanted to.. but I'll try and figure that out.
Thank you.
-
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?
-
Try:
Put in an fgets() call every 24 lines or so....
-
-
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.
-
int main()
{
...
return 0;
}