
/* Example: analysis of text */

#include <stdio.h>

#define MAX 1000 /* The maximum number of characters */

main()
{
  char text[MAX], c;
  int i, lc, uc, dig, oth;
  
  puts("Type some text (then ENTER):");
  
  /* Save typed characters in text[]: */
    
  for (i = 0; i < MAX; i++)
  {
    text[i] = getchar();
    if (text[i] == '\n')
      break;
     
  }
  
  /* Analyse contents of text[]: */
    
  for (i = lc = uc = dig = oth = 0; i < MAX; i++)
  {
    c = text[i];
    if (c >= 'a' && c <= 'z')
      lc++;
    else if (c >= 'A' && c <= 'Z')
      uc++;
    else if (c >= '0' && c <= '9')
      dig++;
    else
    {
      oth++;
       if (c == '\n')
      break;
    }
  }
  
  puts("\nYou typed:");
  printf("\n%i lower case letters\n", lc);
  printf("%i upper case letters\n", uc);
  printf("%i digits\n", dig);
  printf("%i others\n", oth);
}
