-
All replies
-
Helpful answers
-
Aug 6, 2016 8:21 AM in response to Pq101by rccharles,Do you have the correct includes for these functions?
-
Aug 6, 2016 9:17 AM in response to Pq101by VikingOSX,Under the linking section of your project, you want to add Other linker flags : -lncurses.
Here is example code that is a combination of using this 2010 post, and an example from (7. input functions) from the NCURSES Programming Howto site. It compiles cleanly, and runs as it should in the Terminal. It does not launch Terminal from within Xcode and run the code though.
//
// main.c
// ncurse_this
//
// Created by VikingOSX on 8/6/16.
// Copyright © 2016 org.codesmith.us. All rights reserved.
//
#include <stdio.h>
#include <ncurses.h>
#include <string.h>
#define WORLD_WIDTH 50
#define WORLD_HEIGHT 20
int main(int argc, const char * argv[]) {
WINDOW *Win;
int offsetx, offsety;
char mesg[] = "Enter a string: ";
char str[80];
u_long row, col;
initscr();
refresh();
offsetx = (COLS - WORLD_WIDTH) / 2;
offsety = (LINES - WORLD_HEIGHT) / 2;
Win = newwin(WORLD_HEIGHT,
WORLD_WIDTH,
offsety,
offsetx);
box(Win, 0 , 0);
wrefresh(Win);
getmaxyx(stdscr,row,col);
mvprintw(row/2.0, (col-strlen(mesg))/2.0, "%s", mesg);
/* print the message at the center of the screen */
getstr(str);
mvprintw(LINES - 2, 0, "You Entered: %s", str);
getch();
delwin(Win);
endwin();
return 0;
}


