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() ...
Get C Primer Plus, Fourth 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.