Building
That’s enough to start. Let’s try to run it. It’s easy: Click the Run button at the left end of the toolbar, or select Product → Run ( R). It doesn’t matter if you haven’t saved your work; by default Xcode saves everything before it attempts a build. Xcode chugs away at your code for a bit. . . and stops.
- A heads-up placard flashes, saying “Build Failed.”
- The Navigator area switches to the Issue navigator, which shows two items under main.c. (If the Issue navigator doesn’t appear, click the fourth tab at the top of the Navigator area.) One is tagged with a yellow triangle (a warning), and the other with a red octagon (an error). These include descriptions of the errors (Figure 3.2, top).
- When you click one of the items, the editor highlights two lines in main.c. The line that triggered the warning is tagged in yellow, with a banner describing the warning; the error line is in red, with a banner of its own (Figure 3.2, bottom).
Figure 3.2 (top) When Xcode detects build errors, it opens the Issue navigator to display them. (bottom) Clicking an issue focuses the editor on the file and line at which the issue was detected.
It seems the only place where I remembered about interceptions was the format string of the scanf call. The compiler was smart enough to match the number of format specifiers to the number of arguments of the scanf and complain. Similarly, I left off the last parameter to passer_rating, which is an outright error.
You can dash off a fix very quickly:
do { int comps, atts, yards, TDs, INTs; printf("comps, atts, yards, TDs, INTs: "); nArgs = scanf("%d %d %d %d %d", &comps, &atts, &yards, &TDs, INTs); if (nArgs == 5) { float rating = passer_rating(comps, atts, yards, TDs, INTs); printf("Rating = %.1f\n", rating); } } while (nArgs == 5);
To be conservative (I don’t want Xcode to run the program if a warning remains), Product → Build ( B) will compile and link passer-rating without running it. You needn’t have worried: It compiles without error, displaying a “Build Succeeded” placard.