O'Reilly logo

C Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Introductory Program

By now, you probably expect a sample program at the beginning of each chapter, so Listing 4.1 is a program that engages in a dialog with the user. To add a little variety, the code uses the new C99 comment style.

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() { 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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required