C programming in easy steps by McGrath Mike 1956-
Author:McGrath, Mike, 1956-
Language: eng
Format: epub
Tags: C (Computer program language)
Publisher: Southam : In Easy Steps
Published: 2009-03-05T16:00:00+00:00
Don't forget
The program file and custom header file must be located in the same directory but are compiled with the usual command - the compiler reads the header file automatically because of the #include directive.
Hot tip
Notice the use of the %1s format specifier in this example - to read the next character entered by the user.
c
menu.c
Hot tip
An example demonstrating static variables can be found on page 28.
c
action.c
Restricting accessibility
The static keyword can be used to restrict the accessibility of functions to the file in which they are created, in exacdy the same way that static yariables ha\ r e restricted accessibility.
This is recommended practice in larger programs that are spread oyer multiple ".c" files to safeguard against accidental mis-use of functions. For instance, the squareO and multiplyO functions cant be direcdy called from the mainQ function in this example:
o
o e
o
e e
Begin a new program with a preprocessor instruction to
include the standard input/output library functions #include <stdio.h>
Declare a custom function prototype with no arguments void menuQ ;
Add a main function to call the custom function then
return a zero integer as required by the declaration int mainQ
{
menu() ; return 0
}
After the main function block, define the custom function
to pass a menu option as an argument to another function void menu()
int option ;
printf( "\n\tWhat would you like to do?" ) ; printf( "\n\t1. Square a number" ) ; printf( "\n\t2. Multiply two numbers" ) ; printf( "\n\t3. Exit\n" ) ; scanf( "%d" , &option ) ; action( option ) ;
}
Now begin a second program file with a preprocessor to include the standard input/output functions #include <stdio.h>
Next define two simple static functions static square( int a ) { return (a * a) ; } static multiply( int a, int b ){ return a * b ; }
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
NET | C & C++ Windows Programming |
SQL Server | VBA |
Visual Basic |
Deep Learning with Python by François Chollet(12569)
Hello! Python by Anthony Briggs(9914)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9795)
The Mikado Method by Ola Ellnestam Daniel Brolund(9777)
Dependency Injection in .NET by Mark Seemann(9337)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8296)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Grails in Action by Glen Smith Peter Ledbrook(7696)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(7065)
Microservices with Go by Alexander Shuiskov(6825)
Practical Design Patterns for Java Developers by Miroslav Wengner(6746)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6688)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6413)
Angular Projects - Third Edition by Aristeidis Bampakos(6093)
The Art of Crafting User Stories by The Art of Crafting User Stories(5618)
NetSuite for Consultants - Second Edition by Peter Ries(5557)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5360)
Kotlin in Action by Dmitry Jemerov(5062)
