Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Mar 2005 17:21:55 -0600 (CST)
From:      "H. S." <security@revolutionsp.com>
To:        freebsd-hackers@freebsd.org
Subject:   Re: basic programming questions
Message-ID:  <62680.81.84.174.5.1110583315.squirrel@mail.revolutionsp.com>
In-Reply-To: <Pine.NEB.4.53.0503101831520.2171@mercury.qix.co.uk>
References:  <61969.81.84.174.5.1110478195.squirrel@mail.revolutionsp.com> <Pine.NEB.4.53.0503101831520.2171@mercury.qix.co.uk>

next in thread | previous in thread | raw e-mail | index | archive | help
Hey, thanks a lot man, really appreciated :-)

Meanwhile the program has it's base already working, very nice since I
didn't touch C for quite some time now (I used to program when I was
younger, then shifted to system administration and shell scripting), but
I'm enjoying getting things done on my own :)

By the way, you know a link for a good and complete C manual for free ?

Oh, and BTW. I've ran across a problem. I think I knew how to fix this,
but it's beating me right now. Near the end of main() I printf'd some text
and am expecting a y/n response from user. I scanf("%c", &userfeed); right
after, but it printf's and ignores the scanf.

I might know what's going on, some characters on the buffer are not
"cleared", and so scanf is beind fed one of these characters. My memory
says that fflush() should fix this, but it's not working. I've also tried 
getchar() but it didn't work either (or I did it in a wrong way).. I'm
missing something obvious here!

What should I do to correct this? And is my
buffer-not-empty-so-scanf-gets-a-waiting-character theory correct ?


Your curses program and the links the other people gave were great, thanks
to all :)

> On Thu, 10 Mar 2005, H. S. wrote:
>
>>Hey,
>>
>>Sorry if this is a little offtopic, but I need some basic help with C.
>>
>>I'm not a programmer, but I need to get something done in C for a
>> project.
>>I need to do a console application, and as I've got some free time, I'd
>>like to add bold sentences and characters with other colors (ie blue,
>> red,
>>etc), to make it prettier.
>>
>>As my C skills go as far as declaring variables, making loops, and
>> knowing
>>my way around pointers, I really do not know where to start looking for
>>the header file including these functions! I also need a function to
>> clear
>>the screen (in order to re-draw it).
>>
>>Could anyone point me to the right header files, and perhaps suggest some
>>programs that use these functions so I can have something to start with?
>
>
> Here's a little program I just wrote for you:
>
>
> 	#include <curses.h>
>
> 	main()
> 	{
> 	        initscr();
> 	        start_color();
>
> 		/* we want blue text on a white background */
> 	        init_pair(1, COLOR_BLUE, COLOR_WHITE);
> 	        color_set(1, NULL);
>
> 	        clear();
>
> 	        mvprintw(10,20, "Hello, world");
> 	        refresh();
>
> 	        endwin();
> 	}
>
>
> I compiled with:
>
> 	cc -o test test.c -lncurses
>
> and it demonstrates what you want :- clearing the screen and writing text
> in color at a specific location (10 down, 20 across.)
>
> If you don't need to position the text, you can use plain "printw" without
> the x,y.  printw is like printf.
>
> Hope this helps,
>
> Aled
>




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?62680.81.84.174.5.1110583315.squirrel>