954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

counting digits assistance

#include <stdio.h>
cant figure it out, im trying to count all digits
please help with this bugs



int main()
{
    int iochar, numdigits=0, numlower=0, numupper=0, numwhites=0;
	
	printf("Please enter a phrase:\n\n");
	
    while((iochar=getchar())!=EOF) 
	{
        if ((iochar='\o ')||(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\n");
	
	
    return 0;
}
alex1050
Newbie Poster
24 posts since Mar 2011
Reputation Points: 6
Solved Threads: 0
 

Interesting post. You might want to work on your formatting , though. It's inconsistent.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

Hello alex1050,
In the line 15 it looks like '\o'(letter 'o') it should have been '\0'(zero).

Arbus
Practically a Master Poster
615 posts since Dec 2010
Reputation Points: 45
Solved Threads: 31
 

Arbus thanks for that

alex1050
Newbie Poster
24 posts since Mar 2011
Reputation Points: 6
Solved Threads: 0
 

And also it should be == in the if-else (line 15) block as you are comparing the iochar with '\0' etc,.

if ((iochar=='\0')||(iochar=='\t')||(iochar=='\n'))
Arbus
Practically a Master Poster
615 posts since Dec 2010
Reputation Points: 45
Solved Threads: 31
 

And also it should be == in the if-else (line 15) block as you are comparing the iochar with '\0' etc,.

if ((iochar=='\0')||(iochar=='\t')||(iochar=='\n'))

ok, now i just cant figure how to make it count the digits

alex1050
Newbie Poster
24 posts since Mar 2011
Reputation Points: 6
Solved Threads: 0
 

Why? are you getting any errors. The if-else block in line 21 looks correct.

Arbus
Practically a Master Poster
615 posts since Dec 2010
Reputation Points: 45
Solved Threads: 31
 

i dont know im trying to trace it but it should work

alex1050
Newbie Poster
24 posts since Mar 2011
Reputation Points: 6
Solved Threads: 0
 

You have declared iochar as integer type variable. I think that's why you didn't get the output. Declare it as character type variable.

Arbus
Practically a Master Poster
615 posts since Dec 2010
Reputation Points: 45
Solved Threads: 31
 
You have declared iochar as integer type variable. I think that's why you didn't get the output. Declare it as character type variable.


this is what i got Arbus so far....
#include

int main()
{
int iochar, numdigits=0, numlower=0, numupper=0, numwhites=0;
printf("Please enter a phrase: \n");


while((iochar=getchar())!=EOF)
{
if ((iochar==' ')||(iochar=='\t')||(iochar=='\n'))
{
numwhites++;
putchar(iochar);
printf("%d white characters, %d digits, ",numwhites,numdigits);
}
else
if((iochar>='0')&&(iochar<='9'))
{
numdigits++;
putchar(iochar);

}
else
if(('a'<=iochar)&&(iochar<='z'))
{
numlower++;
putchar(iochar);
printf("%d lowercase have been converted to ",numlower);
}
else
if(('A'<=iochar)&&(iochar<='Z'))
{
numupper++;
putchar(iochar);
printf("uppercase and %d uppercase.\n",numupper);
}
else
putchar(iochar);
printf("\n\n");

}


return 0;
}

alex1050
Newbie Poster
24 posts since Mar 2011
Reputation Points: 6
Solved Threads: 0
 

i got it to work but now i want to make all lowercases to uppercases.

alex1050
Newbie Poster
24 posts since Mar 2011
Reputation Points: 6
Solved Threads: 0
 

Look up toupper() and tolower() in your favorite reference material.

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 
Look up toupper() and tolower() in your favorite reference material.


Thanks Lerner...i found it

alex1050
Newbie Poster
24 posts since Mar 2011
Reputation Points: 6
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: