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;
}
If you run your program from the command line, I am pretty sure it will print the prompt.
To do that:
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.
Go back up into the parent folder to reveal the folder containing the program.
Select that folder and open a terminal with the finder command “New Terminal at Folder”
Finally, run the program manually, like this: ./PrintWhoisCool