#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp,*fp1;
char ch,k[4],j[9],c[2];
long beg,end;
clrscr();
if((fp=fopen("input.txt","w"))==NULL)
{
printf("input.txt file opening prblem");
exit(0);
}
if((fp1=fopen("csource.txt","w"))==NULL)
{
printf("csource.txt file opening problem");
exit(0);
}
printf("\n enter the data to send put$ at end \n");
while(1)
{
scanf("%c",&ch);
if(ch=='$')
break;
putc(ch,fp);
}
fclose(fp);
if((fp=fopen("input.txt","r"))==NULL)
{
printf("input.txt file opening problem \n");
exit(0);
}
fputs("DLE STX ",fp1);
while((ch=getc(fp))!=EOF)
{
if(ch=='D')
{
c[0]=getc(fp);
c[1]=getc(fp);
if(c[0]=='L'&&c[1]=='E')
fputs("DLE",fp1);
putc(ch,fp1);
putc(c[0],fp1);
putc(c[1],fp1);
}
else
putc(ch,fp1);
}
fputs(" DLE ETX",fp1);
fclose(fp);
fclose(fp1);
if((fp=fopen("csource.txt","r"))==NULL)
{
printf("csource.txt opening problem");
}
if((fp1=fopen("cdest.txt","w"))==NULL)
{
printf("cdest.txt opening problem");
}
printf("\n data after stuffing \n");
while((ch=getc(fp))!=EOF)
putc(ch,stdout);
fclose(fp);
fp=fopen("csource.txt","r");
beg=ftell(fp);
beg+=9;
fseek(fp,-0L,2);
end=ftell(fp);
end-=8;
fclose(fp);
fp=fopen("csource.txt","r");
printf("data after destuffing \n");
fgets(j,9,fp);
while(beg<=end)
{
ch=getc(fp);
if(ch=='D')
{
c[0]=getc(fp);
c[1]=getc(fp);
if(c[0]=='L'&&c[1]=='E')
{
fgets(k,5,fp);
beg+=5;
}
putc(ch,fp1);
putc(c[0],fp1);
putc(c[1],fp1);
putc(ch,stdout);
putc(c[0],stdout);
putc(c[1],stdout);
beg+=2;
}
else
{
putc(ch,fp1);
putc(ch,stdout);
}
beg++;
}
fclose(fp);
fclose(fp1);
getch();
}
#include<conio.h>
void main()
{
FILE *fp,*fp1;
char ch,k[4],j[9],c[2];
long beg,end;
clrscr();
if((fp=fopen("input.txt","w"))==NULL)
{
printf("input.txt file opening prblem");
exit(0);
}
if((fp1=fopen("csource.txt","w"))==NULL)
{
printf("csource.txt file opening problem");
exit(0);
}
printf("\n enter the data to send put$ at end \n");
while(1)
{
scanf("%c",&ch);
if(ch=='$')
break;
putc(ch,fp);
}
fclose(fp);
if((fp=fopen("input.txt","r"))==NULL)
{
printf("input.txt file opening problem \n");
exit(0);
}
fputs("DLE STX ",fp1);
while((ch=getc(fp))!=EOF)
{
if(ch=='D')
{
c[0]=getc(fp);
c[1]=getc(fp);
if(c[0]=='L'&&c[1]=='E')
fputs("DLE",fp1);
putc(ch,fp1);
putc(c[0],fp1);
putc(c[1],fp1);
}
else
putc(ch,fp1);
}
fputs(" DLE ETX",fp1);
fclose(fp);
fclose(fp1);
if((fp=fopen("csource.txt","r"))==NULL)
{
printf("csource.txt opening problem");
}
if((fp1=fopen("cdest.txt","w"))==NULL)
{
printf("cdest.txt opening problem");
}
printf("\n data after stuffing \n");
while((ch=getc(fp))!=EOF)
putc(ch,stdout);
fclose(fp);
fp=fopen("csource.txt","r");
beg=ftell(fp);
beg+=9;
fseek(fp,-0L,2);
end=ftell(fp);
end-=8;
fclose(fp);
fp=fopen("csource.txt","r");
printf("data after destuffing \n");
fgets(j,9,fp);
while(beg<=end)
{
ch=getc(fp);
if(ch=='D')
{
c[0]=getc(fp);
c[1]=getc(fp);
if(c[0]=='L'&&c[1]=='E')
{
fgets(k,5,fp);
beg+=5;
}
putc(ch,fp1);
putc(c[0],fp1);
putc(c[1],fp1);
putc(ch,stdout);
putc(c[0],stdout);
putc(c[1],stdout);
beg+=2;
}
else
{
putc(ch,fp1);
putc(ch,stdout);
}
beg++;
}
fclose(fp);
fclose(fp1);
getch();
}
No comments:
Post a Comment