problem with incorporating tput in a c program


 
Thread Tools Search this Thread
Top Forums Programming problem with incorporating tput in a c program
# 1  
Old 01-25-2003
problem with incorporating tput in a c program

as you all know, tput is somewhat of a utility that can be used to put the cursor on specific places on the screen. now, I usually use this utility when I do shell programming but I began wondering that there should be a way to put that utility into my c program so I can be able to clear the screen and also display the cursor at where ever i choose.

now, i know this is confusing but please, help me in anyway you can.

heres an idea of what am talking about

you create a file called cursor containing this line:
tput cup $1 $2

you make the file cursor executable.

In an ordinary shell scripting file, if i want to display a line on a screen, all i have to type is something like this:

cursor 16 41; echo "Please enter your salary: "


16 and 41 being the position on the screen i want the line "Please enter your salary" to appear on.

now, how can i do something like that in C. how can i incorporate it in a C programming application.

do i put it in before the int main () function or after or in between.??

thanks
# 2  
Old 01-25-2003
Why not use the ncurses library directly in your C programs?
Documentation included in the source tarball at http://dickey.his.com/ncurses/ncurses.html

I'm not familiar with ncurses programming, but this small code snippet may give you some insights of what this tastes like (it works for me from my cursory glance of the man pages, but the program may not be strictly a correct one)

Code:
#include <curses.h>
#include <unistd.h>

int main(int argc, char* argv[]) {
	
	(void) initscr();
	erase();
	move(4, 3);	/* Move to line 4, col 3 */
	addstr("H E L L O   W O R L D !");	/* print char */
	refresh();
	sleep(5);
	endwin();

	return 0;
}

Compile by

gcc file.c -o executable -lncurses
# 3  
Old 01-26-2003
#include <curses.h>
#include <unistd.h>

int main(int argc, char* argv[]) {

(void) initscr();
erase();
move(4, 3); /* Move to line 4, col 3 */
addstr("H E L L O W O R L D !"); /* print char */
refresh();
sleep(5);
endwin();

return 0;
}




now what i what to know is how do i tweak this program to accept input from the user and do whatever i want to do with it.

to start tweaking it, i assume i'd have to start at the addstr(HELLO WORLD) line. right? if not, please spray me some suggestions
# 4  
Old 01-26-2003
Try the getstr() series of functions in the documentation.

I haven't used ncurses myself, so I can't tell.

You should find what you need in
ncurses-5.3/doc/html/ncurses-intro.html

in the source tarball.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

incorporating a regular expression statement in a shell script (.sh)

I do have a shell file where I call many unix commands . I would like to add a regular expression step in that shell file, where a text file, say Test.txt has to be openned and all the :'s should be replaced. Basically apply the follwoing regular expression: :%s/://g to that particular text... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

2. Shell Programming and Scripting

Help with formatting a menu using tput

I am trying to format a menu using tput. A sample of the menu that i want displayed is the following: printf "***MAIN - MENU***\n" printf " 1. OPTION 1\n" printf " 2. OPTION 2 \n" printf " 3. OPTION 3\n" printf " 4. OPTION 4\n" printf " 5.... (1 Reply)
Discussion started by: goddevil
1 Replies

3. Shell Programming and Scripting

tput // special keys.

$ read -s -N 5 ch; printf "$ch" |od -An -c 033 Obviously during the read I pressed F1. So check something more normal, right-arrow: $ read -s -N 3 ch; printf "$ch" |od -An -c 033 $ tput kcuf1 |od -An -c 033 O C Is my terminal the only broken one? I'm using PuTTY..... (2 Replies)
Discussion started by: neutronscott
2 Replies

4. Shell Programming and Scripting

need help in using tput command

Plz help me in writing a shell script to print * in the form of 8 using tput command ... pattern shud be in d below form... * * * * * * * * * * * * * * * Thanks in advance. (3 Replies)
Discussion started by: Dpu
3 Replies

5. Shell Programming and Scripting

parsing data and incorporating it into another file

Hi, I have a folder that contains many (multiple) files 1.fasta 2.fasta 3.fasta 4.fasta 5.fasta . . 100's of files Each such file have data in the following format for example: vi 1.fasta >AB_1 gi|15835212|ref|NP_296971.1| preprotein translocase subunit SecE... (3 Replies)
Discussion started by: Lucky Ali
3 Replies

6. Shell Programming and Scripting

parsing data and incorporating it into another file

Hi All I have two files: file 1 >AB_1 MLKKPIIIGVTGGSGGGKTSVSRAILDSFPNARIAMIQHDSYYKDQSHMSFEERVKTNYDHPLAFDTDFM IQQLKELLAGRPVDIPIYDYKKHTRSNTTFRQDPQDVIIVEGILVLEDERLRDLMDIKLFVDTDDDIRII RRIKRDMMERGRSLESIIDQYTSVVKPMYHQFIEPSKRYADIVIPEGVSNVVAIDVINSKIASILGEV >AB_2... (5 Replies)
Discussion started by: Lucky Ali
5 Replies

7. Solaris

Getting Started in UNIX - incorporating C coding

I'm just starting a 'serious' coding in UNIX, so what I need is to run a C code on UNIX, What do I have to install (app) prior to coding/running the code and how do I compile that code? can I write my c code in UNIX or I need to have a visual studio for this? (7 Replies)
Discussion started by: Peevish
7 Replies

8. Shell Programming and Scripting

Use of tput ?

what is use of tput smso tput rmso tput sgr0 Thanks (3 Replies)
Discussion started by: dhananjaysk
3 Replies

9. Shell Programming and Scripting

tput clear

What is the difference between these two commands? tput clear /usr/bin/clear (4 Replies)
Discussion started by: whatisthis
4 Replies

10. UNIX for Dummies Questions & Answers

quick question! TPUT!?

:mad: forgot the tput command to make the cursor blink... can any one give me a pointer.. one which command it is.. thanx moxxx68:D (3 Replies)
Discussion started by: moxxx68
3 Replies
Login or Register to Ask a Question