/********************************************************* * From C PROGRAMMING: A MODERN APPROACH, Second Edition * * By K. N. King * * Copyright (c) 2008, 1996 W. W. Norton & Company, Inc. * * All rights reserved. * * This program may be freely distributed for class use, * * provided that this copyright notice is retained. * *********************************************************/ /* length.c (Chapter 7, page 142) */ /* Determines the length of a message */ #include int main(void) { char ch; int len = 0; printf("Enter a message: "); ch = getchar(); while (ch != '\n') { len++; ch = getchar(); } printf("Your message was %d character(s) long.\n", len); return 0; }