Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

C programming - getch() and putch()

I know that if i define <curses> that it will give me some functionality with the getch() function. Let it be noted I am a very baby new programmer and know almost nothing and have almost zero logic. I found the man getch and it mentions something about an ungetch and a wgetch ... are these similar in use to putch? there is no man putch ... google is ambiguous... need help ... please. End desired outcome is me being able to have unbuffered input ...

MacBook Air, macOS High Sierra (10.13.3), C language, programming, putch()

Posted on Mar 2, 2018 7:48 AM

Reply
7 replies

Mar 2, 2018 9:41 AM in response to _circledancer

Your professor is not teaching you how to use buffered vs unbuffered I/O. Your professor is teaching basic programming. In this context, Microsoft Visual Studio is just a learning tool. You should install Windows and Visual Studio on your Mac. I strongly recommend Parallels Desktop Lite on the Mac App Store. It will cost some money, as will Windows. Maybe you can get an educational version of Windows through your school. There are some cheaper, and free, alternatives to Parallels too. My recommendation is just based on my experience.


This is not a question about which platform you will or should use. One of the key questions when developing software is "what are your metrics"? How do you decide if your software is successful? In this case, your professor decides that and will evaluate it in a Windows context. Those are your requirements. Therefore, you need to make sure you fulfill those requirements.


The goal is to learn whatever programming tasks are covered in the class. Those basic programming concepts will apply equally well to the Mac or iOS. The buffered vs unbuffered I/O is just an exercise that is part of the course.

Mar 2, 2018 8:53 AM in response to _circledancer

The ncurses man page lists all of the curses library calls and their particular man page name. The curs_getch (3X) man page discusses getch, ungetch, getch, wgetch, etc. There is man curs_addch (3X) to address writing characters to the screen. There is a separate C library call named putc, or putchar (see man putc), but no putch.


Here is a typical compilation line with Apple's command-line tools, provided that you have the

#include <ncurses.h> in your source file:


clang -O2 -o cur_app cur_app.c -lncurses


Here is the Ncurses programming guide.

Mar 2, 2018 8:44 AM in response to _circledancer

Hello _circledancer,

I don't know if I would recommend curses to a "baby new programmer". Why do you want unbuffered input?


It is traditional for people to start learning in a command line environment. But you don't want to get bogged down in the details of command-line and Terminal I/O. It is easy to do basic reads and prints. Building a real command-line user interface or using unbuffered input can get extremely difficult and tricky.

Mar 2, 2018 8:54 AM in response to etresoft

So i'm in a programming class and unfortunately don't have a choice if I want to use my Mac to code afaik... I'm sure I have a choice.. I am going to attempt and install Eclipse IDE and see if this issue will resolve itself. Maybe that IDE has the proper libraries in a format more similar to windows. Our professor is teaching us how to do buffered vs unbuffered on microsoft vis stuidio and i'm stuck on my mac alone so I'm treading water.

Mar 2, 2018 9:14 AM in response to _circledancer

Why would you sign up for a Windows-based C programming course, and expect to make it through on a Mac? You would be ok as long as the course did not explicitly dip into Windows exclusive functionality.


Apple's macOS does not install a compilation environment. You have two choices: 1) install Apple's Command Line Tools after registering for a free developer account, or 2) use a package manager (e.g. brew.sh) to install GNU C. You will not have an IDE via either approach.


Microsoft offers a free IDE for macOS in Visual Studio Code. I believe that they also offer Visual Studio for Mac as well. The first does not include Microsoft developer libraries, and I am uncertain if the latter completely fills the bill. The Eclipse IDE is not going to do this either, and unless specifically part of your course requirements, I would stay well away from it as it is another layer of learning that you don't need right now.

C programming - getch() and putch()

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