Skip to content

Instantly share code, notes, and snippets.

@rpappalax
Created January 1, 2014 08:34
Show Gist options
  • Save rpappalax/8206254 to your computer and use it in GitHub Desktop.
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
// 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