Compression Data Communication


This program implements Compression. This is a part of Mumbai University MCA Colleges Data Communication and Networking MCA Sem 4 


#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
            int i,j,k,tmp,tmp2;
            int datalen,ctr=0;
            char data[100],encr[100];
            clrscr();
            printf("Enter data : ");
            gets(data);
            printf("\n\nData : ");
            printf("\n%s\n",data);
            printf("\n\nCompressed Data : \n");

            for(i=0;data[i]!='\0';)
            {
                        if(ctr==0)
                        {
                                    tmp=data[i];
                                    ctr++;
                                    i++;
                        }
                        else
                        {
                                    while(tmp==data[i])
                                    {
                                                ctr++;
                                                i++;
                                    }
                                    if(ctr>=4)
                                    {
                                                k=ctr/10;
                                                j=ctr%10;
                                                printf("* %c %d %d",tmp,k,j);
                                                ctr=0;
                                    }
                                    else
                                    {
                                                k=i;
                                                j=i-ctr;
                                                do
                                                {
                                                printf("%c ",data[j]);
                                                j++;
                                                } while(j<k);
                                                tmp2=ctr;
                                                ctr=0;
                                    }
                                    tmp=0;
                        }

            }
            getch();
}


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

No comments:

Post a Comment