answersLogoWhite

0

//Sender

#include<string.h>

#include<stdio.h>

#include<unistd.h>

#include<fcntl.h>

#define SIZE 40

struct frame

{

char str[SIZE+1];

char tmp[2*SIZE];

char flag;

char e;

char final[2*SIZE];

}s;

main()

{int fd,len1;

int i,j,len;

fd=open("b1",O_WRONLY);

printf("\nEnter flag character and escape character for byte-stuffing:");

scanf("%c %c",& s.flag,&s.e);

printf("\nEnter string:");

scanf("%s",s.str);

len=strlen(s.str);

for(i=0,j=0;i<len;i++,j++)

{

if(s.str[i]==s.flag)

{

s.tmp[j]=s.e;

s.tmp[j+1]=s.flag;

j++;

continue;

}

else if(s.str[i]==s.e)

{

s.tmp[j]=s.e;

s.tmp[j+1]=s.e;

j++;

continue;

}

else

{

s.tmp[j]=s.str[i];

}

}

printf("\nAppended string is==>%s \n",s.tmp);

len1=strlen(s.tmp);

for(i=0,j=0;i<=len1;i++,j++)

{

if((i==0)(i==len1))

{

s.final[j]=s.flag;

s.final[j+1]=s.tmp[i];

j++;

continue;

}

else

{

s.final[j]=s.tmp[i];

}

}

printf("\nFianal string is==>%s\n",s.final);

write(fd,&s,sizeof(s));

}

//Reciver

#include<string.h>

#include<stdio.h>

#include<unistd.h>

#include<fcntl.h>

#define SIZE 40

struct frame

{

char str[SIZE+1];

char tmp[2*SIZE];

char flag;

char e;

char final[2*SIZE];

}r;

main()

{

int fd,len1;

int i,j,len;

mknod("b1",010666,0);

fd=open("b1",O_RDONLY);

read(fd,&r,sizeof(r));

printf("\nFlag character is==>%c\n",r.flag);

printf("\nEscape character is ==>%c\n",r.e);

printf("\nAnd actual message was ==>%s\n",r.str);

printf("\nReceived message is %s\n\n",r.final);

}

/*****************

[mca222@rcclinux mca222]$ cc -os byte_s.c

[mca222@rcclinux mca222]$ cc -or byte_r.c

[mca222@rcclinux mca222]$ ./r&

[1] 1570

[mca222@rcclinux mca222]$ ./s

Enter flag character and escape character for byte-stuffing:#

@

Enter string:sim#andh@ar

Sending message is==>#sim@#andh@@ar#

Flag character is==>#

Escape character is ==>@

And actual message was ==>sim#andh@ar

Received message is #sim@#andh@@ar#

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

Byte stuffing program in c?

teri bhen ki.....................


What are the benefits of data stuffing?

The following data fragment occurs in the middle of a data stream for which the byte-stuffing algorithm described in the text is used: A B ESC C ESC FLAG FLAG D. What is the output after stuffing?


Write a program in c language to implement framing methods like character stuffing?

A program in c language to implement framing methods like character stuffing can be grave sizeCRC-32 and the variable c50.


What are the Example Output of Calculator Program in C plus plus?

example output of c++ calculator


What has the author Bijan Mashaw written?

Bijan Mashaw has written: 'C++ programming byte by byte' 'Programming byte by byte' -- subject(s): FORTRAN 77 (Computer program language), Structured programming 'BASIC' -- subject(s): BASIC (Computer program language)


How is memory allocated in c program for a character data type?

One byte for every character.


How do you program C keyboard output to kind of press the keys for you?

The answer to this will be platform and implementation dependent. For Windows machines, look into the keybd_event function: VOID keybd_event( BYTE bVk, // virtual key code BYTE bScan, // hardware scan code DWORD dwFlags, // special flags PTR dwExtraInfo // whether the key is pressed or released );


How do you store the data into byte in c?

There is not built-in 'byte' type in C, but you can define it: typedef unsigned char byte; byte bmin=0, bmax=255;


Write a c program to have followiing as output?

void main() { printf("followiing"); }


C program on how to calculate circumference of a circle?

int radius = 2; int output; radius = radius * 2; output = radius * Math.PI; Console.WriteLine(output);


How do you create a program that will display output?

It must use a function with a "return" statement. Or you could output via console. (.NET CODE(C#)) Console.WriteLine("Output.");


How do you capture the output of C program in to another C program?

HIYou can first include the 1st program in ur 2nd program using # include and then whatever be the output from frst it can be used in second program.pankajThat's what popen is good for. Read the manual.