Unix Programming - A curses question.

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > February 2006 > A curses question.





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author A curses question.
Roka100@gmail.com

2006-02-20, 8:49 pm

Hi all,
Here is a simple program of curses.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <stddef.h>
#include <curses.h>

/**************** MAIN ROUTINE *******************/
int main(int argc,char *argv[]/*,char **genv*/){
const char witch_one[] = "First witch";
const char witch_two[] = "Second witch";
const char *scan_ptr;

initscr();

move(5,15);
attron(A_BOLD); /* turn on attr of BOLD */
printw("%s","Macbeth");
attroff(A_BOLD); /* turn off */
refresh();
sleep(1);

move(8,15);
attron(A_DIM);
printw("%s","Thunder and Linghtning");
attroff(A_DIM);
refresh();
sleep(1);

move(10,10);
printw("%s","Shen shall we three meet again");
move(11,23);
printw("%s","In thunder ,lighting, or in rain?");
move(13,10);
printw("%s","When the hurlyburly's done,");
move(14,23);
printw("%s","When the battle's lost and won.");
refresh();
sleep(1);

attron(A_DIM);
scan_ptr = witch_one + strlen(witch_one);
while(scan_ptr != witch_one){
move(10,10);
insch(*scan_ptr--);
refresh();
sleep(1);

}
scan_ptr = witch_two + strlen(witch_two);
while(scan_ptr != witch_two){
move(13,10);
insch(*scan_ptr--);
refresh();
sleep(1);
}
attroff(A_DIM);
refresh();
sleep(1);

endwin();

return 0;

}

And result is:
Macbeth


Thunder and Linghtning

irst witch^@Shen shall we three meet again
In thunder ,lighting, or in rain?

econd witch^@When the hurlyburly's done,
When the battle's lost and won.

---------------------------
My question is Why "irst witch^@" be outputted ? What is "^@" ??(There
should be a '\0' .)

thanks.

Hubble

2006-02-21, 2:49 am

>My question is Why "irst witch^@" be outputted ? What is "^@" ??(There
> be a '\0' .)


Your curses seems to outout ^A, ^B, ... for CRTL-A, CTRL-B. Note that
ASCII A is 65, ASCII B is 66 a.s.o but CTRL-A is 1, CTRL-B is 2, so
CTRL-x is ASCII-x-64.

ASCII-@ is 64, so Code 0 is equal CTRL-@ and presented as ^@.

> scan_ptr = witch_two + strlen(witch_two);
> while(scan_ptr != witch_two){
> ...


use

scan_ptr = witch_two + strlen(witch_two)-1;
while(scan_ptr >= witch_two){
...

if you want to start with the last visible character.

Hubble.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com