[C] Character counter

By A^1^T^E^A^M on Feb 11, 2009

This little program will gather all entered characters and determine how many numeric characters there are, alpha characters and special punctuation chars, including spaces!

Image

/* Programmer: Boris Kuzmanov alias A^1^T^E^A^M (Gravedigger) */
#include <stdio.h>
#include <ctype.h>

int main()
{
      char ch;
      int num_ch, num_num, spec_num;

      num_ch = 0;
      num_num = 0;
      spec_num = 0;

      printf("Print characters: ");

          while((ch = getchar()) != '\n')
             {

                    if(isalpha(ch))
                         num_ch++;
                    else if(isdigit(ch))
                         num_num++; 
                    else if(ispunct(ch))
                         spec_num++;
                    else if(isspace(ch))
                         spec_num++;
             }

          printf("\nThere are %d letters in the string!", num_ch);
          printf("\nThere are %d numbers in the string!", num_num);
          printf("\nThere are %d special characters in the string!\n", spec_num);

      system("Pause");
      return 0;
}

Comments

Sign in to comment.
NIGathan   -  Apr 02, 2009

rofl at the 'cu​nter' tag. Nice code, happen to know if the isalpha(), isdigit(), ..etc functions are in a C++ header?

Nvm I found it, its in locale

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.