简体   繁体   中英

OSX Command Line Readln equvilent

I'm just starting playing with some programming for OSX, and trying to create a simple command line app but I can't seem to find a good guide. Basically I want to know how to get some user input for example ask the user their age etc.

You're in luck; OS X provides a manual page on all (nearly all?) standard C functions; the only trouble is knowing which function provides the services you're looking for. The fgets() function is probably best for reading a line-at-a-time. You'll use it something like this:

char buffer[MAXLINE];
if (fgets(buffer, MAXLINE, stdin) != NULL) {
    /* handle line in buffer */
}

If you're really looking for a tutorial , The C Programming Language is one of the finest possibilities. Be sure to get the second edition -- a first edition might be entertaining, but the language has changed too drastically for it to be a reliable guide.

If you want a reference, then your manpages are the best source of information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM