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

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

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

Edited 5 Years Ago by Arbus: n/a

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.

Edited 5 Years Ago by Arbus: n/a

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

Edited 5 Years Ago by alex1050: n/a

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.

Edited 5 Years Ago by Arbus: n/a

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

Edited 3 Years Ago by mike_2000_17: Fixed formatting

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

Thanks Lerner...i found it

This article has been dead for over six months. Start a new discussion instead.