basic programming questions

H. S. security at revolutionsp.com
Fri Mar 11 15:22:30 PST 2005


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
>




More information about the freebsd-hackers mailing list