LinuxQuestions.org
Register a domain and help support LQ
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 03-20-2011, 09:19 AM   #31
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714

@shivi91

It looks like you want graphics, not colored text. (Why didn't you clearly say that anywhere?!?)
There are two main kinds of graphics/GUI libraries:

First are GUI toolkits (typically used for desktop applications). They provide you with buttons, labels, text entries, and just about any other control you can think of. You can also create your own widget (control) and draw in it. The main choices are GTK+ (or its C++ binding, gtkmm) and Qt.

And second there are game libraries (typically used for video games). They mostly handle only image files and are made for drawing complex scenes made out of lots of them really fast. They also often provide functions for audio and input devices, and some support 3D graphics. Popular ones for Linux include SDL and Allegro.
 
1 members found this post helpful.
Old 03-20-2011, 12:32 PM   #32
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
shivi91: Your code demonstrates that you are trying to produce a GUI. You have code which renders pixel graphics to a computer monitor, and you have code that acquires input from an interactive user.
Code:
/* draw a rectangle */

rectangle(left,top,right,bottom);

/* clean up */

getch();
To create GUIs in Linux, you can proceed in one of at least two ways. You can use one of the common GUI toolkits, such as GTK or Qt. Or you can develop your own GUI, building your own widgets and so on from a lower level library or libraries. While this seems to be the method demonstrated by your code, I would consider it by far the least desirable approach.

Your code will never compile and run under Linux directly. There are no libraries that directly implement the semantics given in your code. The Turbo C graphics library is a very poor and incomplete toolkit for developing any kind of GUI (and is the reason that things like Windows and X-Windows were designed). The Turbo C graphics library is targeted to a very specific architecture; one which is very dissimilar to most architectures found on common Linux desktop environments. Your best hope to run the code you posted (ever think of posting in [CODE ] tags?) might be to run it in some kind of emulator. For that, you would need to build it with the native Turbo C compiler.

--- rod.
 
Old 03-20-2011, 01:23 PM   #33
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
Quote:
Originally Posted by theNbomr View Post
To create GUIs in Linux, you can proceed in one of at least two ways. You can use one of the common GUI toolkits, such as GTK or Qt. Or you can develop your own GUI, building your own widgets and so on from a lower level library or libraries. While this seems to be the method demonstrated by your code, I would consider it by far the least desirable approach.
I agree. Writing GUI elements yourself is a waste of time, and will never come close to the functionality, look, and feel of a real toolkit.

Just check out GTK+ and Qt, pick one (personally I think Qt is easier to work with and has more features), and use it. They even have nice GUI programs to build the interface of your program before you even start writing code (Qt Designer for Qt, and Glade for GTK+).

Last edited by MTK358; 03-20-2011 at 01:25 PM.
 
Old 03-21-2011, 12:51 PM   #34
shivi91
LQ Newbie
 
Registered: Mar 2011
Location: india
Posts: 24

Original Poster
Rep: Reputation: 0
dos.h doesn't work either..what should be done for that?
 
Old 03-21-2011, 01:01 PM   #35
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
There is no direct equivalent of dos.h in standard C.

Instead, use this: http://en.wikipedia.org/wiki/Libc

Last edited by MTK358; 03-21-2011 at 01:04 PM.
 
Old 03-21-2011, 01:13 PM   #36
shivi91
LQ Newbie
 
Registered: Mar 2011
Location: india
Posts: 24

Original Poster
Rep: Reputation: 0
Quote:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
main()
{

int ch;

char pword[8];

int i = 0;



cout << endl << " Enter system password : ";

fflush(stdout);



while ((ch = getch()) != EOF && ch != '\n' && ch != '\r' && i < sizeof(pword))

{

if (ch == '\b' && i > 0)

{

printf("\b \b");

fflush(stdout);

i--;

pword[i] = '\0';

}

else if (isalnum(ch))

{

putchar('*');

pword[i++] = (char)ch;

}

}

pword[i] = '\0';

if(strcmp(pword, "Teacher8")==1)
cout<<"workd";

}




while ((ch = getch()) != EOF && ch != '\n' && ch != '\r' && i < sizeof(pword))//how would this be converted to linux code..
 
Old 03-21-2011, 01:16 PM   #37
shivi91
LQ Newbie
 
Registered: Mar 2011
Location: india
Posts: 24

Original Poster
Rep: Reputation: 0
i want the input to be stars like inputing password... that was the code which worked in turbo..
 
Old 03-21-2011, 01:33 PM   #38
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
Quote:
Originally Posted by shivi91 View Post
while ((ch = getch()) != EOF && ch != '\n' && ch != '\r' && i < sizeof(pword))//how would this be converted to linux code..
Is "pword" a variable name or some kind of data type found in Turbo C/dos.h?

Please post the code in BBCode [code]code goes here[/code] tags. It will use a monospaced font and preserve indentation.

Quote:
Originally Posted by shivi91 View Post
i want the input to be stars like inputing password... that was the code which worked in turbo..
EDIT: There is no nice, cross-platform way of preventing typed characters from being echoed. If you will only use the GNU implementation of libc (glibc, used in almost all Linux systems), then you can use this: http://www.gnu.org/s/libc/manual/html_node/getpass.html

Last edited by MTK358; 03-21-2011 at 01:40 PM.
 
Old 03-22-2011, 08:32 AM   #39
shivi91
LQ Newbie
 
Registered: Mar 2011
Location: india
Posts: 24

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by MTK358 View Post
Is "pword" a variable name or some kind of data type found in Turbo C/dos.h?
l[/url]
pwrod is a varible..that is like the password we trying to enter
 
Old 03-22-2011, 08:56 AM   #40
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
Did you read the part of my post about not echoing, and did you understand it? (By the way, why do you keep ignoring so many of our questions? I still don't understand what you meant by "graphics" or what you want to do!)

From what I understand, this should do what you want (warning: not tested). Requires you to include termios.h.

Code:
struct termios termios_old, termios_new;

if (tcgetattr(fileno(stdin), &termios_old) != 0) {
	// stuff to do if failed to get terminal settings
}
termios_new = termois_old;
termios_new.c_lflag &= ~ECHO;
if (tcgetattr(fileno(stdin), TCSAFLUSH, &termios_new) != 0) {
	// stuff to do if failed to set terminal settings
}

// typed characters will not echo now

tcgetattr(fileno(stdin), TCSAFLUSH, &termios_old);

// typed characters will echo again now
 
  


Reply

Tags
c++, graphics


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] ATI graphics on Fedora 14 Dagorath Linux - Hardware 3 03-03-2011 07:55 AM
Graphics problem in fedora 10.. RAJEEV N BHARSHETTY Linux - Newbie 1 09-09-2009 10:01 AM
What are you using for a graphics card in Fedora? moxieman99 Fedora 3 03-19-2009 12:56 PM
graphics.h in fedora kantu Linux - Newbie 1 10-14-2008 01:26 PM
fedora 3 problem with graphics anjani.78 Linux - Newbie 8 07-05-2005 10:53 AM


All times are GMT -5. The time now is 12:38 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration