How to compile c in xcode?

I have recently started using Xcode and i am unable to use getch() ,clrscr() etc functions to compile c code. Is there a way to make it work.

MacBook Pro, OS X El Capitan (10.11.6)

Posted on Aug 6, 2016 6:39 AM

Reply
2 replies

Aug 6, 2016 9:17 AM in response to Pq101

Under the linking section of your project, you want to add Other linker flags : -lncurses.

User uploaded fileUser uploaded file


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;

}

User uploaded file

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to compile c in xcode?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.