Thread: Color Program (no help required)

  1. #1
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533

    Color Program (no help required)

    because these forums are mainly used for help, I wanted to enrich the environment with a little program I am working on, I have one that has more code but this is the program before I added to it. A nice color interface!

    Code:
    #include <stdio.h>
    
    #define RESET		0
    #define BRIGHT 		1
    #define DIM		2
    #define UNDERLINE 	3
    #define BLINK		4
    #define REVERSE		7
    #define HIDDEN		8
    
    #define BLACK 		0
    #define RED		1
    #define GREEN		2
    #define YELLOW		3
    #define BLUE		4
    #define MAGENTA		5
    #define CYAN		6
    #define	WHITE		7
    
    void textcolor(int attr, int fg, int bg);
    int main()
    {
    	char ans;
    	system("clear");
    	printf("\t\t\t\t");
    	textcolor(BRIGHT,BLUE,BLACK);
    	printf("Welcome!");
    	textcolor(RESET,WHITE,BLACK);
    	printf("\nTest!\n");
                    // Menu plus more functions here
    	printf("Do you want to continue? [y/n]: ");
    	scanf("%c",&ans);
    	printf("%c\n",ans);
    	if(ans == 'y' )
    	{
    		printf("good!"); //more code here
    	}
    	else
    	{
    		printf("bad!"); // more code here
    	}
    	printf("\n");
    	return 0;
    }
    
    void textcolor(int attr, int fg, int bg)
    {	char command[13];
    
    	/* Command is the control command to the terminal */
    	sprintf(command, "%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40);
    	printf("%s", command);
    }
    // more functions here
    
    //basically I commented out the stuff I had in the bigger program
    the original source was found on some website, I will post it as soon as I find it, the true author of textcolor() should get credit.
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  2. #2
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    you forgot to include stdlib.h!!!!!
    you should be punished.
    anyway, it's cool...it gives attitude to my konsole

  3. #3
    Registered User stautze's Avatar
    Join Date
    Apr 2002
    Posts
    195
    If you didn't write textcolor, what did you write that is so great besides a poor yes/no interface. Try this:

    Code:
    typedef enum boolean { FALSE, TRUE } Boolean;
    
    Boolean UserSaysYes(void)
    {
         int  c;
    
        printf(" (y,n)? ");
        do {
            while ((c = getchar()) == '\n');
            if (c == 'y' || c == 'Y' || c == 'n' || c == 'N')
                return (c == 'y' || c == 'Y');
            printf("Please respond by typing one of the letters y or n\n");
        } while (1);
    }

  4. #4
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    we can all see your trying to look cool by putting in complecated code, right?
    WELL IT AINT WORKIN

  5. #5
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    oh thats nice, but thats not complicated.
    Want to see my EDUMP Module for the 2.2 Kernel?
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  6. #6
    Registered User stautze's Avatar
    Join Date
    Apr 2002
    Posts
    195
    >we can all see your trying to look cool by putting in complecated code, right?

    yep

  7. #7
    Registered User stautze's Avatar
    Join Date
    Apr 2002
    Posts
    195
    BTW LP no offense intended, it was three in the morning and homework was taking me way longer than I expected. I thought I had seen that code in a linux mag somewhere, and I was just trying to be an arse. Not necessary...

  8. #8
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    actually, that wasn't my intention...
    I posted it because I was really bored, so I searched for something interesting on linux programming and added a line or two and posted it, just a reason to post something. (Hint: wanted to reach Senior Member sooner)

    the code really isn't complicated if you read the article that came with it.
    no, here is something complicated...
    (not really, just annoying)
    Code:
    #include <stdio.h>
    int main()
    {
    	int x,_x,__x,x__;printf("\n"); scanf("%d",&_x);scanf("%d",&__x);x__ = __x++;
    	x = (_x++) - (__x - x__);if(x>__x){ return 0; }	for(;x<__x;x++){  if(x = __x-1)
    	{ printf("\ndone\n");}}
    	return 0;
    }
    sorry if I am annoying anyone, I am really bored.
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  9. #9
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    Originally posted by Xterria
    you forgot to include stdlib.h!!!!!
    you should be punished.
    anyway, it's cool...it gives attitude to my konsole
    umm, on my compiler.... stdlib.h isn't required for this program to run or compile succesfully.
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  10. #10
    Unregistered
    Guest
    Originally posted by Xterria
    you forgot to include stdlib.h!!!!!
    you should be punished.
    anyway, it's cool...it gives attitude to my konsole
    ^lamer!

    dont worry bout this kid all he posts is garbage...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. Lvalue required error
    By eklavya8 in forum C Programming
    Replies: 5
    Last Post: 01-03-2009, 04:47 PM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. NAQ: Everything you never wanted to know about CPP
    By evildave in forum C Programming
    Replies: 21
    Last Post: 12-12-2005, 10:56 AM
  5. is this required in a function body?
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 09-26-2001, 03:20 PM