Introductory Program

By now, you probably expect a sample program at the beginning of each chapter, and I won't disappoint you. Listing 4.1 presents a program that engages in a dialogue with the user.

Listing 4.1 The talkback.c program.
 /* talkback.c -- nosy, informative program */ #include <stdio.h> #include <string.h> /* for strlen() prototype */ #define DENSITY 62.4 /* human density in lbs per cu ft */ int main(void) { float weight, volume; int size, letters; char name[40]; /* name is an array of 40 chars */ printf("Hi! What's your first name?\n"); scanf("%s", name); printf("%s, what's your weight in pounds?\n", name); scanf("%f", &weight); size = sizeof name; letters = strlen(name); volume = weight / DENSITY; printf("Well, %s, your volume ...

Get C Primer Plus®, Third 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.