Thread: My first "real" program.......is really smal is mostly for practice.

  1. #16
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Not Sure how "legal" this is, but this is DevC++, if anything blame Denethor2000
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #17
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    thx... whenever I try to use em in mine it gives me an unresolved external symbol error

  3. #18
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >go into ur conio.h and place the code here?
    The chances of that working aren't very good and the chances of your compiler choking and not letting you compile at all are pretty good. You'd be better off just going with Windows functions.
    Code:
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    int main ( void )
    {
      HANDLE h;
      h = GetStdHandle ( STD_OUTPUT_HANDLE ); 
      SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_GREEN ); 
      cout<<"My ";
      SetConsoleTextAttribute ( h, FOREGROUND_RED );
      cout<<"next ";
      SetConsoleTextAttribute ( h, FOREGROUND_GREEN );
      cout<<"rant ";
      SetConsoleTextAttribute ( h, FOREGROUND_INTENSITY | FOREGROUND_BLUE );
      cout<<"will ";
      SetConsoleTextAttribute ( h, FOREGROUND_INTENSITY | FOREGROUND_RED );
      cout<<"be ";
      SetConsoleTextAttribute ( h, FOREGROUND_INTENSITY | FOREGROUND_GREEN );
      cout<<"in ";
      SetConsoleTextAttribute ( h, FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED );
      cout<<"technicolor ";
      SetConsoleTextAttribute ( h, FOREGROUND_BLUE | FOREGROUND_GREEN );
      cout<<"rainbow :D"<<endl;
      SetConsoleTextAttribute(h, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);
      return EXIT_SUCCESS;
    }
    -Prelude
    My best code is written with the delete key.

  4. #19
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Hey Prelude any recommendations on my coding style? Please......
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  5. #20
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    The conio.h doesn't work because all it has are function prototypes, structs, enums, ect. But, it does not have actual function implementations. Those are found elsewhere and are linked to the .h normally(at least thats what i think).

  6. #21
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    As I said before anything blame it on Denethor2000 LMAO lol....


    Code:
    #ifndef _CONIO_C_
    #define _CONIO_C_
    
    /* Please keep all functions alphabetical! */
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <windows.h>
    #include "conio.h"
    
    int __FOREGROUND = LIGHTGRAY;
    int __BACKGROUND = BLACK;
    
    void _setcursortype(int _type) {
      CONSOLE_CURSOR_INFO Info;
      Info.bVisible = TRUE;
      if (_type == _NOCURSOR)
         Info.bVisible = FALSE;
      else if (_type == _SOLIDCURSOR)
         Info.dwSize = 100;
      else if (_type == _NORMALCURSOR)
         Info.dwSize = 1;
      SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), &Info);
    }
    
    void clreol() {
      /* What does this function do? */
    }
    
    void clrscr() {
      COORD coord;
      DWORD written;
      CONSOLE_SCREEN_BUFFER_INFO info;
    
      coord.X = 0;
      coord.Y = 0;
      GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
      FillConsoleOutputCharacter (GetStdHandle(STD_OUTPUT_HANDLE), ' ',
        info.dwSize.X * info.dwSize.Y, coord, &written);
      gotoxy (1, 1);
    }
    
    int cputs(const char *_str) {
      printf ("%s\n", _str);
      return 0;
    }
    
    int getche() {
      int ch;
      ch = getch ();
      printf ("%c\n", ch);
      return ch;
    }
    
    void gettextinfo(struct text_info *_r) {
      CONSOLE_SCREEN_BUFFER_INFO Info;
      GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &Info);
      _r->winleft = Info.srWindow.Left;
      _r->winright = Info.srWindow.Right;
      _r->wintop = Info.srWindow.Top;
      _r->winbottom = Info.srWindow.Bottom;
      _r->attribute = Info.wAttributes;
      _r->normattr = LIGHTGRAY | BLACK;
    /*  _r->currmode = ; */ /* What is currmode? */
      _r->screenheight = Info.dwSize.Y;
      _r->screenwidth = Info.dwSize.X;
      _r->curx = wherex ();
      _r->cury = wherey ();
    }
    
    void gotoxy(int x, int y) {
      COORD c;
      c.X = x - 1;
      c.Y = y - 1;
      SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
    }
    
    void gppconio_init() {
      /* Do nothing */
    }
    
    void highvideo() {
      if (__FOREGROUND <= BROWN)
         textcolor (__FOREGROUND + 9);
      if (__BACKGROUND <= BROWN)
         textbackground (__BACKGROUND + 9);
    }
    
    void insline() {
      printf ("\n");
    }
    
    int putch(int _c) {
      printf ("%c", _c);
      return _c;
    }
    
    void textattr(int _attr) {
      SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), _attr);
    //  printf ("%d\n", text_info.screenheight);
    }
    
    void textbackground(int _color) {
      if (_color == BLINK)
         _color = WHITE;
      __BACKGROUND = _color;
      textattr (__FOREGROUND | (_color + 29));
    }
    
    void textcolor(int _color) {
      if (_color == BLINK)
         _color = WHITE;
      __FOREGROUND = _color;
      textattr(_color | __BACKGROUND);
    }
    
    int wherex() {
      CONSOLE_SCREEN_BUFFER_INFO info;
      GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
      return info.dwCursorPosition.X;
    }
    
    int wherey() {
      CONSOLE_SCREEN_BUFFER_INFO info;
      GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
      return info.dwCursorPosition.Y - 2;
    }
    
    void window(int _left, int _top, int _right, int _bottom) {
      SMALL_RECT R;
      R.Left = _left;
      R.Top = _top;
      R.Right = _right;
      R.Bottom = _bottom;
      SetConsoleWindowInfo (GetStdHandle(STD_OUTPUT_HANDLE), TRUE, &R);
      gotoxy (_left, _top);
    }
    
    #endif _CONIO_C_
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  7. #22
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    does the namespace part have to be there for it to work? because it says std isnt a real namespace

  8. #23
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Hey Prelude any recommendations on my coding style?
    Start taking advantage of loops so that you can make the program shorter. There are two extremes, one is too compact and the other is way too much code for something simple. What you need to do is find a happy medium that is easy to read but not exhausting.

    -Prelude
    My best code is written with the delete key.

  9. #24
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Thanks.....
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  10. #25
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    Maybe you can help me with this -

    typing(char* Text, int speed){
    HANDLE h;
    h = GetStdHandle ( STD_OUTPUT_HANDLE );

    for (int i = 0;Text[i] != '\0';i++)
    {
    Text[i - 1] = SetConsoleTextAttribute(h, FOREGROUND_INTENSITY);

    cout << Text[i]<< flush;
    Sleep(speed);
    }
    return EXIT_SUCCESS;

    }

    this was supposed to type out char by char a sting, and as it goes along.. first type it in normal gray, then next letter would be normal gray, but the PREVIOUS would be darker gray. Like a shine running along the words as they come out. get it? could you plz help?

  11. #26
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Sorry that looks like Win32 and I don't know it yet......I am planning to start learning it as soon as I finish this book though I am in chapter 19 out of 21.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  12. #27
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Code:
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    #define WHITE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
    
    int main ( void )
    { 
      HANDLE h;
      char Text[] = "This is a long stream of text with alternating colors";
      int speed = 100;
      h = GetStdHandle ( STD_OUTPUT_HANDLE );
      for (int i = 0;Text[i] != '\0';i++) {
        if ( i & 1 )
          SetConsoleTextAttribute ( h, FOREGROUND_INTENSITY );
        else
          SetConsoleTextAttribute ( h, WHITE );
        cout<<Text[i];
        Sleep(speed);
      }
      SetConsoleTextAttribute ( h, WHITE );
      cout<<endl;
      return EXIT_SUCCESS;
    }
    -Prelude
    My best code is written with the delete key.

  13. #28
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    ErGG! Thx for try, but i knew how to do that, with switch statements btw (feels proud)

    but i want to know how to make it so like each new character becomes the head(which will be white) and then after a new character is added in front of it that one becones white, and the one that was previously the head goes back to normal colors, so like the ONLY white letter is the newest character, which will then be grey when another letter pops in front of it. kinda like a worm with a white head and a gray body. get it?

    ty in advance ^_^

  14. #29
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Piece of cake, but you will have to make use of the gotoxy function that is defined in the Cprogramming FAQ.
    Code:
    #include <iostream>
    #include <windows.h>
    #include "myConio.h"
    using namespace std;
    
    #define WHITE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY
    
    int main ( void )
    {
      int y = 0;
      HANDLE h;
      char Text[] = "This is a long stream of text with alternating colors";
      int speed = 50;
      h = GetStdHandle ( STD_OUTPUT_HANDLE );
      for (int i = 1;Text[i-1] != '\0';i++) {
        SetConsoleTextAttribute ( h, WHITE );
        cout<<Text[i-1];
        gotoxy ( i-1, y );
        Sleep(speed);
        SetConsoleTextAttribute ( h, FOREGROUND_INTENSITY );
        cout<<Text[i-1];
        gotoxy ( i, y );
        Sleep(speed);
      }
      SetConsoleTextAttribute ( h, WHITE );
      cout<<endl;
      return EXIT_SUCCESS;
    }
    -Prelude
    My best code is written with the delete key.

  15. #30
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    erm,, r we 4getting sumthin? i dont have gotoxy !!!...

    maybe you could post an alternate for it up here plz?

Popular pages Recent additions subscribe to a feed

Similar Threads

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