LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-18-2004, 06:07 PM   #1
shadow.blue
Member
 
Registered: Jan 2003
Distribution: gentoo (2.6.5-gentoo)
Posts: 73

Rep: Reputation: 15
noob needs help with console output (c++)


Hi,

I`m trying to create a typewriter effect, which reads a message and displays the output of it
like you would be writing on a typewriter... I think you know what I mean...

Code:
#include <iostream>
#include <unistd.h>
#include <string.h>

int main()

{
        char message[]="Message to be displayed...";
        
        for (int i=0;i<strlen(message);i++)
        {
                                 
                std::cout << message[i] << std::flush;
                usleep(200000); 
        }
        return 0;
}
It works for the function that it puts the lines out char by char...

The thing is... I need a blinking prompt always in front of the character.
Like if you log onto your box, you see the input prompt and the cursor (it may not be blinking at all on your machine, but I think you know what I mean, hehe)

I searched for a function to buffer the output and flush it to make it visible and invisible... bla I am just totally stuck on this one.

Hope someone can help me on this...
 
Old 04-18-2004, 11:27 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
You should be able to do it with the ncurses library. Look for the curs_set method:

http://en.tldp.org/HOWTO/NCURSES-Pro...WTO/index.html

I found some source here that implements a flashing cursor for some sort of a typing tutor program.

http://cvs.sourceforge.net/viewcvs.p...Fplain&rev=1.4
 
Old 04-19-2004, 07:43 AM   #3
shadow.blue
Member
 
Registered: Jan 2003
Distribution: gentoo (2.6.5-gentoo)
Posts: 73

Original Poster
Rep: Reputation: 15
Thanks for this hint.

I`ll take some time now to dig into the ncurses docs.
 
Old 04-19-2004, 10:29 AM   #4
shadow.blue
Member
 
Registered: Jan 2003
Distribution: gentoo (2.6.5-gentoo)
Posts: 73

Original Poster
Rep: Reputation: 15
Hi,

I fiddled around with ncurses, but I have one problem I just don`t
get across...

Whever I run this program, I gives me a segmentation fault.
When I change message[i] to message to print the whole message,
it works. But when I want to print each char of the array, it breaks....



Code:
#include <ncurses.h>
#include <unistd.h>
#include <string.h>

int main()
{

        char message[]="Testmessage 1 2 3";

        initscr();


        for (int i=0;i<strlen(message);i++)
        {

                printw("%s",message[i]);
                refresh();
                usleep(200000);
        }



        endwin();
        return 0;
}
Hope you can help me on this one...
 
Old 04-19-2004, 01:55 PM   #5
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Use a "%c" in your printw.
 
Old 04-19-2004, 03:58 PM   #6
shadow.blue
Member
 
Registered: Jan 2003
Distribution: gentoo (2.6.5-gentoo)
Posts: 73

Original Poster
Rep: Reputation: 15
doh!

Thank you very much. you saved my day


BTW: is it possible to use ncurses library with python?
 
Old 04-19-2004, 04:35 PM   #7
kooch
Member
 
Registered: Mar 2004
Location: Upstate NY
Distribution: Slackware/YDL
Posts: 77

Rep: Reputation: 15
yup

http://www.python.org/doc/current/li...le-curses.html
 
Old 04-19-2004, 05:24 PM   #8
shadow.blue
Member
 
Registered: Jan 2003
Distribution: gentoo (2.6.5-gentoo)
Posts: 73

Original Poster
Rep: Reputation: 15
Good.

... I just switched
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Different color for console error output? ta0kira Linux - Software 0 05-18-2005 07:22 AM
program console output using C xrado Programming 5 04-04-2005 02:48 PM
How to disable console output kamel Programming 2 06-02-2004 01:41 PM
Console output to X? dcm1878 Linux - Software 4 04-23-2003 08:07 PM
Long console output Loke Linux - Newbie 1 02-26-2003 06:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration