Thread: Character count program

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    19

    Character count program

    I have the character count program that works like it should, but I can't figure out code to count the number of non-alphanumeric characters. Non alphanumeric characters are !@#$%^&*() basically they are any characters that do not contain the value of a number or a letter. Is there code to find non-alphanumeric characters?

    Code:
    #include<stdio.h>
    #include<conio.h>
    
    void main()
    {
    int length=0,upper=0,lower=0,digits=0;
    char str[80];
    char strlen[80];
    int i;
    
    printf("\nEnter The String : ");
    gets(str);
    
    
    i=0;
    
    while(strlen[length]!='\0')
            length++;
    
    while(str[i]!='\0')
      {
      if(str[i]>='A' && str[i]<='Z')
         upper++;
      if(str[i]>='a' && str[i]<='z')
         lower++;
      if(str[i]>='0' && str[i]<='9')
    	 digits++;
    
      i++;
      }
    
     printf("\nLength of the String is : %d",length);
     printf("\nUppercase Letters : %d",upper);
     printf("\nLowercase Letters : %d",lower);
     printf("\nDigits : %d",digits);
    
    
    
        getch();
     }

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Do you want to "roll your own", or use the standard functions?

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    19

    Character count program

    Standard functions

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I believe you have the answer <from the other forum>. no 's' in ctype.h

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. mandelbrot set program improvements
    By mad_muppet in forum Game Programming
    Replies: 3
    Last Post: 07-14-2010, 05:58 AM
  2. Program crashing when replacing newline character
    By mdekom12 in forum C Programming
    Replies: 2
    Last Post: 05-01-2010, 08:49 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Character stack ADT program
    By alice in forum C Programming
    Replies: 1
    Last Post: 07-05-2004, 04:30 AM