While You're at It…Multiple Functions

So far, these programs have used the standard printf() function. Listing 2.3 shows you how to incorporate a function of your own—besides main()—into a program.

Listing 2.3 The two_func.c program.
/* two_func.c -- a program using two functions in one file */
#include <stdio.h>
void butler (void);            /* ANSI C function prototyping */
                   /* pre-ANSI C uses void butler(); instead */
int main(void)
{
   printf(I will summon the butler function.\n);
   butler();
   printf(Yes. Bring me some tea and writeable CD-ROMS.\n);[sr]
   return 0;
}
void butler(void)            /* start of function definition */
{
   printf("You rang, sir?\n");
}

The output looks like this:

 I will summon the butler function. You rang, sir? Yes. Bring me some tea and ...

Get C Primer Plus®, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.