question: How do I implement a basic CUI in c++?

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

32 Replies - 3726 Views - Last Post: 02 October 2012 - 07:57 PM Rate Topic: -----

#1 booleanbalaji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 28-September 12

question: How do I implement a basic CUI in c++?

Posted 28 September 2012 - 07:56 PM

The specifications state that I am allowed to use only the 1998 standard of c++.Its for a school project.
Also,
How can I change the background of the output screen? Do i need to use graphics.h?
How can I continuously read input from the user without the need to wait for the return key to be pressed?
How to read backspace character?
Is This A Good Question/Topic? 0
  • +

Replies To: question: How do I implement a basic CUI in c++?

#2 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1687
  • View blog
  • Posts: 3,206
  • Joined: 30-May 10

Re: question: How do I implement a basic CUI in c++?

Posted 28 September 2012 - 10:33 PM

Well the answer to all your questions depends on your OS and compiler.
So, which OS and compiler are you using?
Was This Post Helpful? 0
  • +
  • -

#3 booleanbalaji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 28-September 12

Re: question: How do I implement a basic CUI in c++?

Posted 29 September 2012 - 01:58 AM

View PostSalem_c, on 28 September 2012 - 10:33 PM, said:

Well the answer to all your questions depends on your OS and compiler.
So, which OS and compiler are you using?

Using Windows and Turbo c++ running on dos box
Was This Post Helpful? 0
  • +
  • -

#4 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1687
  • View blog
  • Posts: 3,206
  • Joined: 30-May 10

Re: question: How do I implement a basic CUI in c++?

Posted 29 September 2012 - 02:40 AM

> The specifications state that I am allowed to use only the 1998 standard of c++
...
> Turbo c++
TC++ isn't even close to being compliant to C++98.
Was This Post Helpful? 4
  • +
  • -

#5 Ticon  Icon User is offline

  • D.I.C Regular

Reputation: 28
  • View blog
  • Posts: 320
  • Joined: 20-August 09

Re: question: How do I implement a basic CUI in c++?

Posted 29 September 2012 - 01:29 PM

First off, id tell you to yell at your instructor for using outdated crap. Second
is this of any help?

http://www.programme...8/Download.aspx
Was This Post Helpful? 0
  • +
  • -

#6 booleanbalaji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 28-September 12

Re: question: How do I implement a basic CUI in c++?

Posted 29 September 2012 - 09:47 PM

View PostTicon, on 29 September 2012 - 01:29 PM, said:

First off, id tell you to yell at your instructor for using outdated crap. Second
is this of any help?

http://www.programme...8/Download.aspx


It'd be great if I could do that. The problem is the the program should run with turbo c++. I am using c free standard for all my needs, using a Borland c++ compiler. Graphics doesn't work with this. I also tried changing the text colour and the background, but it just simple does not work.
Was This Post Helpful? 0
  • +
  • -

#7 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 802
  • View blog
  • Posts: 2,363
  • Joined: 20-March 10

Re: question: How do I implement a basic CUI in c++?

Posted 29 September 2012 - 10:13 PM

does this code work on Turbo C ?

#include <windows.h>

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "CodeBlocksWindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpszArgument,
                     int nCmdShow)
{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Code::Blocks Template Windows App",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nCmdShow);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}




Regards

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#8 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1687
  • View blog
  • Posts: 3,206
  • Joined: 30-May 10

Re: question: How do I implement a basic CUI in c++?

Posted 30 September 2012 - 12:10 AM

> I am using c free standard for all my needs, using a Borland c++ compiler.
Trust me, your tutor can't tell the difference between a language standard and a barrel of bricks. Unfortunately, it's you that will be feeling all the pain when you get out into the real world, and find that all the stuff you've been taught is useless (and all the years of wasted opportunity).

Download a modern compiler (visual studio, code::blocks, pelles-c) and get some decent books:
http://www.dreaminco...338-books-on-c/
Use this to learn something useful (in your own time).
The diploma at the end of your course is barely good enough to open the door for your first job. You'll need something else to be able to keep that job.

> How can I change the background of the output screen? Do i need to use graphics.h?
http://www.programmi...nio.h/textcolor
> How can I continuously read input from the user without the need to wait for the return key to be pressed?
Try getch();
> How to read backspace character?
Try getch();

Have you ever opened conio.h in your text editor and read through all the functions it offers?
Was This Post Helpful? 1
  • +
  • -

#9 booleanbalaji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 28-September 12

Re: question: How do I implement a basic CUI in c++?

Posted 01 October 2012 - 09:10 PM

View PostSalem_c, on 30 September 2012 - 12:10 AM, said:

> I am using c free standard for all my needs, using a Borland c++ compiler.
Trust me, your tutor can't tell the difference between a language standard and a barrel of bricks. Unfortunately, it's you that will be feeling all the pain when you get out into the real world, and find that all the stuff you've been taught is useless (and all the years of wasted opportunity).

Download a modern compiler (visual studio, code::blocks, pelles-c) and get some decent books:
http://www.dreaminco...338-books-on-c/
Use this to learn something useful (in your own time).
The diploma at the end of your course is barely good enough to open the door for your first job. You'll need something else to be able to keep that job.

> How can I change the background of the output screen? Do i need to use graphics.h?
http://www.programmi...nio.h/textcolor
> How can I continuously read input from the user without the need to wait for the return key to be pressed?
Try getch();
> How to read backspace character?
Try getch();

Have you ever opened conio.h in your text editor and read through all the functions it offers?

Actually I know about some of the functions in conio but not really found the need to use them till now.
Was This Post Helpful? 0
  • +
  • -

#10 booleanbalaji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 28-September 12

Re: question: How do I implement a basic CUI in c++?

Posted 01 October 2012 - 09:22 PM

And one more thing. I need continuous input of characters from the keyboard. What I am doing is, getting input from the user and writing it simultaneously to a text file. I can use flush(), but when I use getch(), it requires me to press the return key to give the input...
Was This Post Helpful? 0
  • +
  • -

#11 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,159
  • Joined: 05-May 12

Re: question: How do I implement a basic CUI in c++?

Posted 01 October 2012 - 10:36 PM

If you truly do know about the conio functions as you claim you do, then you can call kbhit() to see if there is any input pending in the input buffer, and if so, then you can safely call getch() and the runtime library will not wait on the user.
Was This Post Helpful? 0
  • +
  • -

#12 booleanbalaji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 28-September 12

Re: question: How do I implement a basic CUI in c++?

Posted 01 October 2012 - 10:46 PM

Does kbhit() get the input or simply detect the input? Can I read backspace using it?
Was This Post Helpful? 0
  • +
  • -

#13 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,159
  • Joined: 05-May 12

Re: question: How do I implement a basic CUI in c++?

Posted 01 October 2012 - 11:42 PM

I feel that if your teachers are making you use Turbo C, they are under the obligation to provide you copies of the old Turbo C manuals as well.

I threw out my Turbo C manuals long ago, but as I recall, kbhit() will return non-zero as long as there is something in the keyboard buffer, including pending backspace keypresses.

This post has been edited by Skydiver: 01 October 2012 - 11:42 PM

Was This Post Helpful? 0
  • +
  • -

#14 booleanbalaji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 28-September 12

Re: question: How do I implement a basic CUI in c++?

Posted 01 October 2012 - 11:58 PM

Okay, but that isn't going to help me. I tried using getch() and it works perfectly.
Next is the backspace
Was This Post Helpful? 0
  • +
  • -

#15 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,174
  • Joined: 08-January 12

Re: question: How do I implement a basic CUI in c++?

Posted 02 October 2012 - 02:10 AM

I have never seen a Turbo-C++ manual! I also want one! :cry2:

And yes, kbhit() returns non-zero value if there is anything in the buffer to read.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3