The officially official Devuan Forum!

You are not logged in.

#1 2019-03-25 19:23:39

fabien
Member
Registered: 2019-03-11
Posts: 13  

Ncurses

Hello!

I am trying to learn a bit C (only for fun), and I wrote a little code with ncurses.

It works on FreeBSD, but I can't run it on DEVUAN.

libncurses5-dev and libncursesw5-dev are installed, the program compile just fine but nothing shows up in the terminal.

Is somebody knows what I am talking about?

Merci.

Fabien

Offline

#2 2019-03-30 21:22:54

fabien
Member
Registered: 2019-03-11
Posts: 13  

Re: Ncurses

Hi,

Sorry to insist, nobody?

Offline

#3 2019-03-30 21:57:32

dxrobertson
Member
Registered: 2017-05-04
Posts: 232  

Re: Ncurses

I have no experience with ncurses.

You say "the program compile just fine", just to make sure - you did compile it on Devuan?

How are you running it, from a terminal?  Are any error messages displayed in the terminal? 

If you are sure its running, and there are no errors anywhere, then I would add printf's in your code to see where your program is at runtime:

printf("HERE 1.\n");
...
printf("HERE 2.\n");
...

Offline

#4 2019-03-30 21:58:18

ralph.ronnquist
Administrator
From: Battery Point, Tasmania, AUS
Registered: 2016-11-30
Posts: 1,251  

Re: Ncurses

You do know how to leave an audience guessing wink

Perhaps you should test the waters at the freenode IRC #devuan as well, to increase the chances of running into someone else doing C with ncurses on both freebsd and devuan. It might be a more select group than this one.

Offline

#5 2019-03-30 22:11:17

fabien
Member
Registered: 2019-03-11
Posts: 13  

Re: Ncurses

dxrobertson wrote:

I have no experience with ncurses.

You say "the program compile just fine", just to make sure - you did compile it on Devuan?

How are you running it, from a terminal?  Are any error messages displayed in the terminal? 

If you are sure its running, and there are no errors anywhere, then I would add printf's in your code to see where your program is at runtime:

printf("HERE 1.\n");
...
printf("HERE 2.\n");
...

Hi, i did compile it on Devuan using Geany.

There is no error message.

I will try your tip, thank you! I should of do it already, i am afraid i am a bit slow  smile

Thank you!

Offline

#6 2019-03-30 22:16:24

fabien
Member
Registered: 2019-03-11
Posts: 13  

Re: Ncurses

ralph.ronnquist wrote:

You do know how to leave an audience guessing wink

Perhaps you should test the waters at the freenode IRC #devuan as well, to increase the chances of running into someone else doing C with ncurses on both freebsd and devuan. It might be a more select group than this one.

I hope I wasn't rude.

Thank you I will try that too smile

Last edited by fabien (2019-03-30 22:16:41)

Offline

#7 2019-03-30 22:42:50

yeti
Member
From: I'm not here: U R halucinating
Registered: 2017-02-23
Posts: 334  

Re: Ncurses

Where is the code?


*๐š›๐š’๐š‹๐š‹๐š’๐š!*

Offline

#8 2019-03-30 23:03:51

fabien
Member
Registered: 2019-03-11
Posts: 13  

Re: Ncurses

Thank you for helping.

#include <time.h>
#include <ncurses.h>
WINDOW *create_newwin(int h, int l, int y, int x)
{	WINDOW *local_win;

	local_win = newwin(h, l, y, x);
	box(local_win, 0 , 0);		
	wrefresh(local_win);		

	return local_win;
}
int main(int argc, char **argv)
{
	WINDOW *win;
	int x, y, h, l;                          // window
	int px, py;								 // chicken
	int v1x;								 // car 1
	int ch, top = 0;								 
	initscr();	
	cbreak();					
	keypad(stdscr, TRUE);		
	nodelay(stdscr, TRUE);
	curs_set(0);							  
	
	h = 30;
	l = 60 ;
	y = (LINES - h) / 2;		
	x = (COLS - l) / 2;	
	py = 1;
	px = 30;
	v1x = 1;		
	
	while ((ch = getch()) != 'q' && (py != 10 || px != v1x)){                                
		
		if (clock() > top + 10){   
			top = clock();
			win = create_newwin(h, l, y, x);  // car crossing the window
			mvwhline(win, 10, 1, '.', 58);
			mvwaddch(win, 10, v1x, 'V');
			v1x++;
			if (v1x > 58)
				v1x = 1;
		}

		switch(ch){                            // chicken moves
			case KEY_LEFT:
				px--;
				break;
			case KEY_RIGHT:
				px++;
				
				break;
			case KEY_UP:
				py--;
				break;
			case KEY_DOWN:
				py++;
				break;	
		}

		mvwaddch(win, py, px,'P');                  
		wrefresh(win);
		mvwaddch(win, py, px,' ');
	}

	endwin();
	return 0;
}

Offline

#9 2019-03-30 23:21:27

yeti
Member
From: I'm not here: U R halucinating
Registered: 2017-02-23
Posts: 334  

Re: Ncurses

~/tmp4c$ cat /etc/devuan_version 
ascii
~/tmp4c$ ls -l
total 4
-rw-r--r-- 1 yeti yeti 1293 Mar 30 23:05 main.c
~/tmp4c$ gcc main.c -lncurses -o main
~/tmp4c$ ls -l
total 16
-rwxr-xr-x 1 yeti yeti 9216 Mar 30 23:14 main
-rw-r--r-- 1 yeti yeti 1293 Mar 30 23:05 main.c

It compiles without errors.
Started with

~/tmp4c$ ./main 

it runs and I can move the P with the arrow keys.

Last edited by yeti (2019-03-30 23:26:12)


*๐š›๐š’๐š‹๐š‹๐š’๐š!*

Offline

#10 2019-04-01 06:24:46

fabien
Member
Registered: 2019-03-11
Posts: 13  

Re: Ncurses

Ah...
Thank you, I will check that.

Offline

Board footer