November 2013
Beginner
325 pages
9h 47m
English
Sometimes you need a variable to hold several related chunks of data. In C, you can do this with a structure, commonly called a struct. Each chunk of data is known as a member of the struct.
For example, consider a program that computes a person’s Body Mass Index, or BMI. BMI is a person’s weight in kilograms divided by the square of the person’s height in meters. (BMI is a very imprecise tool for measuring a person’s fitness, but it makes a fine programming example.)
Create a new project: a C Command Line Tool named BMICalc. Edit main.c to declare a struct named Person that has two members: a float named heightInMeters and an int named weightInKilos. Then create two Person structs:
#include <stdio.h> // Here is ...
Read now
Unlock full access