Created
January 1, 2014 08:34
-
-
Save rpappalax/8206254 to your computer and use it in GitHub Desktop.
Determine the length of a message.
Uses well-known idiom for determining end of line.
source: http://knking.com/books/c2/programs/length2.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Determine the length of a message | |
#include <stdio.h> | |
int main(void) | |
{ | |
int len = 0; | |
printf("Enter a message: "); | |
while (getchar() != '\n') | |
len++; | |
printf("Your message was %d character(s) long.\n", len); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment