So, the first chapter in Stephen Prata’s book “C Primer Plus”. Since there are no exercises in it (only one, theoretical), I will give a small summary of the chapter for the purpose of familiarization:
The advent of the C language
1972 at Bell Labs by Dennis Ritchie.
Reasons for the popularity of the C language
- Design features
– top-down planning
– structured programming
– modular design
- Efficiency: compact and fast (only assembler is faster)
Disadvantages of the C programming language
the possibility of software errors that are difficult to track down and the complexity of the code to understand.
C language standards
- K&R C or Classic C (classic C)
- First ANSI/ISO standard
- C99 standard
- C11 standard
The Seven Steps of C Programming
- definition of program objectives
- program design
- writing code
- running the program for execution
- program testing and debugging
- maintenance and modification of the program
Commenting code in C
– in order not to get cumbersome, poorly functioning and difficult to understand programs.
- .c source code file → compilation → object code file
- object file+libraries+startup code → link → .exe file
Problem: Disappears from the screen immediately after the program terminates
Solution: getchar(); getchar();
You have just been hired by MacroMuscle, Inc. Company
enters the European market and wishes to have at its disposal a program
which converts inches to centimeters (1 inch is 2.54 cm). Company
wants the program to prompt the user for a value
in inches. Your task is to determine the objectives of the program and
develop a draft program (stages 1 and 2 of the programming process).
The purpose of the program: the conversion of units of measurement. The program needs to receive from the user numerical values of length in inches, which will be re-read using a mathematical formula in centimeters; after which the user will be shown the new length value in centimeters.
Interface: to begin with, the program needs to display information on the user’s screen about what this program does; then ask the user to enter the numeric value in inches they wish to convert to centimeters. Having received data from the user and shortchanged them, the program displays the result to the user.
Organization of the program: (given that this chapter does not say anything about variables and how the code is structured, this point is simplified at this stage):
- opening text: Welcome to inches-to-cm calculator! Please enter value in inches
- value request: <user enters value n>
- value recalculation: <value is recalculated according to the formula (n*2.54)>
- output: Result: n inches is … centimetres
I will be glad to see your comments!