Readline() command question

Hello,

When I run the example code for the readline() function in chapter 8, it won’t print "Who is cool? " until I have first entered the user input
Example: (user input it bold)

Mikey
Who is cool? Mikey
Mikey is cool!

The example in the book shows

Who is cool? Mikey
Mikey is cool!

I’m wondering how do I make it display "Who is cool? " first without needing to put in any input?

Here is my code on Xcode:

#import <readline/readline.h>
#import <stdio.h>

int main(int argc, const char * argv[]) {
    printf("Who is cool? ");
    const char *name = readline(NULL);
    printf("%s is cool!\n\n", name);
    return 0;
}

Thank you :slight_smile:

If you run your program from the command line, I am pretty sure it will print the prompt.

To do that:

  1. Go to the folder containing the program.
    In Xcode open the Products group, and select the program, then bring up the context-sensitive menu and select Show in Finder.

  2. Go back up into the parent folder to reveal the folder containing the program.

  3. Select that folder and open a terminal with the finder command “New Terminal at Folder”

  4. Finally, run the program manually, like this: ./PrintWhoisCool

Hope this helps the Objective-C programmer in you :slight_smile:

Yes it worked fine that way! Thanks for your help ibex!! :smile: