Rle Encoding...What's the wrong?

Posted by FILIaS on Stack Overflow See other posts from Stack Overflow or by FILIaS
Published on 2010-03-21T00:14:03Z Indexed on 2010/03/21 0:21 UTC
Read the original article Hit count: 692

Filed under:
|
|
|

I'm trying to make a Rle Encoder Programme.I read the way it works on notes on net. And i tried to fix my code! Regardless I think that the structure and logic of code are right,the code doesnt work! It appears some strange 'Z' as it runs. I really cant find what;s wrong! Could u please give me a piece of advice? Thanx in advance...

#include <stdio.h>

int main()
{
    int count;
    unsigned char currChar,prevChar=EOF;
    while(currChar=getchar() != EOF)
    {
        if ( ( (currChar='A')&&(currChar='Z') ) || ( (currChar='a')&&(currChar='z') ) )
        {
            printf("%c",currChar);
            if(prevChar==currChar)
            {
                count=0;
                currChar=getchar();
                while(currChar!='EOF')
                {
                    if (currChar==prevChar)
                        count++;
                    else
                    {   
                        if(count<=9)
                            printf("%d%c",count,prevChar);
                        else
                        {   
                            printf("%d%c",reverse(count),prevChar);
                        }                       
                        prevChar=currChar;
                        break;
                    }
                }
            }
            else
                prevChar=currChar;

            if(currChar=='EOF')
            {   printf("%d",count);
                break;
            }
        }
        else
        {
            printf("Error Message:Only characters are accepted! Please try again! False input!");
            break;
        }
    }
    return 0;
}

int reverse(int x)
{
    int piliko,ypoloipo,r=0;
    x=(x<0)?-x:x;
    while (x>0)
    {
        ypoloipo=x%10;
        piliko=x/10;
        r=10*r+ypoloipo;
        x=piliko;
    }
    printf("%d",r);
    return 0;
}

© Stack Overflow or respective owner

Related posts about c

    Related posts about encoding