When the contents of your main.c file match what you see above, it’s time to run your program and see what it does. This is a two-step process. Xcode builds your program and then runs it. When building your program, Xcode prepares your code to run. This includes checking for syntax and other kinds of errors.
Look again at the lefthand area of the Xcode window. This area is called the navigator area. At the top of the navigator area is a series of buttons. You are currently viewing the project navigator, which shows you the files in your project. The project navigator’s icon is .
Now find and click the button to reveal the log navigator. The log is Xcode’s way of communicating with you when it is building and running your program.
You can also use the log for your own purposes. For instance, the line in your code that reads
printf("It was the best of times.n");
is an instruction to display the words “It was the best of times.” in the log.
Since you haven’t built and run your program yet, there isn’t anything in the log navigator. Let’s fix that. In the upper lefthand corner of the project window, find the button that looks suspiciously like the Play button in iTunes or on a DVD player. If you leave your cursor over that button, you’ll see a tool tip that says Build and then run the current scheme. That is Xcode-speak for “Press this button, and I will build and run your program.”
If all goes well, you’ll be rewarded with the following:
If not, you’ll get this:
What do you do then? Carefully compare your code with the code in the book. Look for typos and missing semicolons. Xcode will highlight the lines it thinks are problematic. After you find the problem, click the Run button again. Repeat until you have a successful build.
(Don’t get disheartened when you have failed builds with this code or with any code you write in the future. Making and fixing mistakes helps you understand what you’re doing. In fact, it’s actually better than lucking out and getting it right the first time.)
Once your build has succeeded, find the item at the top of the log navigator labeled Debug AGoodStart. Click this item to display the log from the most recent run of your program.
The log can be quite verbose. The important part is the Dickens quote at the end. That’s your code being executed!
GNU gdb 6.3.50-20050815 (Apple version gdb-1705) (Tue Jul 5 07:36:45 UTC 2011) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys001 [Switching to process 2723 thread 0x0] It was the best of times. It was the worst of times.
(As I’m writing this, Apple is working on a new debugger called LLDB. Eventually it will replace GDB, the current debugger. If you aren’t seeing all the GDB information, it means that LLDB is now Xcode’s standard debugger. The future must be a terrific place; I envy you.)