EmbLogic's Blog

enter a string and compress with the help of masterarray

head    1.1;
access;
symbols;
locks; strict;
comment    @ * @;

1.1
date    2014.03.23.21.53.35;    author root;    state Exp;
branches;
next    ;

desc
@master array with compression
@

1.1
log
@Initial revision
@
text
@#include<stdio.h>
#include<string.h>
#include<fcntl.h>
int main()
{
int i=0,j,len,maslen=1,fd,ret;
char arr[100]={0};
char masterarr[25]={0};
fd=open(“add.c”,O_RDONLY);
if(fd<0)
{
perror(“open”);
goto OUT;
}
printf(“fd=%d\n”,fd);

ret=read(fd,&arr[i],1);
for(i=1;ret>0;i++)
{
ret=read(fd,&arr[i],1);
printf(“\nret=%d,data is %c\n”,ret,arr[i]);
}

len=strlen(arr);
unsigned int ch1,ch2,comp,fd1;
for(i=0;i<len;i++)
{
for(j=0;j<maslen;j++)
{
if(j+1==maslen)
{
masterarr[j]=arr[i];
maslen++;
break;
}
else
{
if(masterarr[j]==arr[i])
break;
}
}
}
printf(“masterarr=%s\n”,masterarr);
fd1=open(“compress”,O_CREAT|O_RDWR,777);
if(fd<0)
{
perror(“open”);
goto OUT;
}

for(i=0;i<len;i++)
{
for(j=0;j<maslen;j++)
{
if(masterarr[j]==arr[i])
{
ch1=j;
break;
}
}
i++;
for(j=0;j<maslen;j++)
{
if(masterarr[j]==arr[i])
{
ch2=j;
break;
}
}
printf(“value in ch1 %d\n and ch2 %d\n”,ch1,ch2);

ch2=ch2<<4;
comp=ch1|ch2;
printf(“comp=%d”,comp);
write(fd1,&comp,1);
}
return 0;
OUT:
return-1;
}

@

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>