O'Reilly logo

C Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. Th two_func.c Program
/* two_func.c -- a program using two functions in one file */
#include <stdio.h>
void butler(void);      /* ISO/ANSI C function prototyping */
int main(void)
{
   printf("I will summon the butler function.\n");
   butler();
   printf("Yes. Bring me some tea and writeable CD-ROMS.\n");
   return 0;
}

void butler(void)          /* start of function definition */
{
   printf("You rang, sir?\n");
}

The output looks like the following:

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

The butler() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required