#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;
}

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

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

Arbus thanks for that

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'))

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

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

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

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.

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 <stdio.h>



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;
}

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

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

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

Thanks Lerner...i found it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.