C Programming Absolute Beginner's Guide (3rd Edition)

(Romina) #1
for (i=0; i < ctr; i++)
{
printf("%s rated a %d!\n", movies[i], movieratings[i]);
}
return(0);
}

Here is a sample output from this program:


Click here to view code image


*** Oscar Season 2012 is here! ***
Time to rate this year's best picture nominees:
Did you see Amour? (Y/N): Y
What was your rating on a scale of 1-10: 6
Did you see Argo? (Y/N): Y
What was your rating on a scale of 1-10: 8
Did you see Beasts of the Southern Wild? (Y/N): N
Did you see Django Unchained? (Y/N): Y
What was your rating on a scale of 1-10: 7
Did you see Les Miserables? (Y/N): Y
What was your rating on a scale of 1-10: 7
Did you see Life of Pi? (Y/N): N
Did you see Lincoln? (Y/N): Y
What was your rating on a scale of 1-10: 6
Did you see Silver Linings Playbook? (Y/N): Y
What was your rating on a scale of 1-10: 9
Did you see Zero Dark Thirty? N
** Your Movie Ratings for the 2012 Oscar Contenders **
Silver Linings Playbook rated a 9.
Argo rated a 8.
Les Miserables rated a 7.
Django Unchained rated a 7.
Lincoln rated a 6.
Amour rated a 6.

Figure 25.2 shows how the program sets up the movies array in memory. Each element is nothing
more than a character pointer that contains the address of a different person’s name. It’s important to
understand that movies does not hold strings—just pointers to strings.

Free download pdf