Thread: Counting Digits & Numbers

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    63

    Counting Digits & Numbers

    This program is suppose to count whitespace, digits, uppercase and lowercase letters and convert them to opposites. Any ideas what's wrong here?

    Code:
    #include <stdio.h>
    
    int main(void)
    {
        int iochar, numdigits=0, numlower=0, numupper=0, numwhites=0;
    
        printf("Please enter a phrase:\n\n");
        
        while((iochar=getchar())!=EOF) 
        {
            if ((iochar=' ')||(iochar='\t')||(iochar='\n'))
            {
            numwhites++;
            putchar(iochar);
            }
            else if((iochar>='0')&&(iochar<='9')) 
            {
            numdigits++;
            putchar(iochar);
            }
            else if(('a'>=iochar)&&(iochar<='z')) 
            {
            numlower++;
            putchar(iochar-32);
            } 
            else if(('A'>=iochar)&&(iochar<='Z'))
            {
            numupper++;
            putchar(iochar);
            }
            else putchar(iochar);    
        }
        
        printf("%d white characters, %d digits, ", numwhites, numdigits);
        printf("%d lowercase have been converted to ", numlower);
        printf("uppercase and %d uppercase.\n", numupper);
        
        printf("\n");
        
        return 0;
    }

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    What output are you getting, and how does that differ from what you expected?

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    63
    It's converting everything to white space it seems and then just counts the white space. The result of all the other nums is 0.

    When i compile there is also a warning w8060 - possibly incorrect assignment in function main.

  4. #4
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Code:
    if ((iochar=' ')||(iochar='\t')||(iochar='\n'))

  5. #5
    Registered User
    Join Date
    Oct 2010
    Posts
    63
    Wow, = instead of ==

    Thanks Bayint Naung!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. Help needed with VERY large numbers.
    By jwarner in forum C++ Programming
    Replies: 4
    Last Post: 01-18-2004, 12:01 PM
  3. Counting Page Numbers
    By dayknight in forum C++ Programming
    Replies: 2
    Last Post: 11-11-2002, 06:52 AM
  4. Counting Occurrance of Numbers
    By dat in forum C Programming
    Replies: 6
    Last Post: 11-03-2002, 02:11 PM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM