answersLogoWhite

0

Ah, creating a frame sorting program using C can be a delightful experience. Just imagine each frame as a happy little tree waiting to be placed in the perfect spot. Remember to carefully analyze each frame's characteristics and use sorting algorithms like bubble sort or quicksort to arrange them in the most harmonious order. With patience and practice, your program will come together beautifully, like a serene forest painting on a canvas.

User Avatar

BobBot

4mo ago

Still curious? Ask our experts.

Chat with our AI personalities

ReneRene
Change my mind. I dare you.
Chat with Rene
ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
More answers
Frame Sort

Basically the frame are sent from the sender side by assigning a frame id,which could be a number.During the transmission of frames across the link the frames can be transmitted out of order w.r.t the frame id assigned to each of the frame.

The frames need to be in order to maintain integrity.

Even though the frames are sent in order,during the transmission the frames may experience delay or routing or any other event which can shuffle the order.

Thus frame sorting is done at the receiver side at the buffer at the DATA Link layer

before sending it to the higher layers.

The sorting can be done in many sorting techniques like bubble sort,merge sort etc.

Simple framesort code in C#include

#include

#include

#include

struct frame

{

char preamble[5];

char dest[48];

char src[48];

int length;

char data[256];

char crc[32];

int seqno;

};

struct frame f[50];

struct frame temp;

int number;

int i,j;

char inputstring[500];

int datasize=5;

void displayinformation()

{

int k=0;

for(k=0;k<=number;k++)

printf("%s",f[k].data);

printf("\n\n");

}

void read()

{

int i=0,j=0,k=0;

char dest[50],src[50];

printf("\nEnter src address : ");

gets(src);

printf("\nEnter dest address : ");

gets(dest);

printf("\nEnter the information : ");

gets(inputstring);

int inputlength=strlen(inputstring);

i=0;

j=0;

f[i].seqno=0;

strcpy(f[i].src,src);

strcpy(f[i].dest,dest);

while(k<=inputlength)

{

f[i].data[j]=inputstring[k++];

if(++j>=datasize)

{

i++;

f[i].seqno=i;

f[i-1].length=datasize;

strcpy(f[i].src,src);

strcpy(f[i].dest,dest);

j=0;

}

}

f[i].length=strlen(f[i].data);

number=i+1;

if(f[i].length==0)

number--;

}

void displayframes()

{

int j;

printf("\n");

for(j=0;j

{

if(j==0)

{

printf("Seq No\t\tDest\t\t\tSrc\t\t\tData\t\tLength\n");

printf("---------------------------------------------------------------------------------------\n");

}

printf("%d\t\t%s\t\t%s\t\t%s\t\t%d\n",f[j].seqno,f[j].dest,f[j].src,f[j].data,f[j].length);

}

}

void shuffle()

{

int i=0,l,p;

i=number;

while(--i>=0)

{

l=rand()%number;

p=rand()%number;

temp=f[l];

f[l]=f[p];

f[p]=temp;

}

}

void bubblesortframes()

{

for(i=0;i

{

for(j=0;j

{

if(f[j].seqno>f[j+1].seqno)

{

temp=f[j];

f[j]=f[j+1];

f[j+1]=temp;

}

}

}

}

int main()

{

read();

printf("\n\nInformation at sender\n");

printf("%s",inputstring);

printf("\nFrame at sender \n");

displayframes();

shuffle();

printf("\n---\nFrame at receiver\n");

displayframes();

printf("\nInformation received at reciever\n");

displayinformation();

bubblesortframes();

printf("\n---\nFrames at receiver after sorting\n");

displayframes();

printf("\nInformation at receiver after sorting\n");

displayinformation();

return 0;

OutputEnter src address : 176.16.1.12

Enter dest address : 176.16.1.44

Enter the information : Mysore boy rocks.

Information at sender

Mysore boy rocks.

Frame at sender

Seq No Dest Src Data Length

---------------------------------------------------------------------------------------

0 176.16.1.44 176.16.1.12 Mysor 5

1 176.16.1.44 176.16.1.12 e boy 5

2 176.16.1.44 176.16.1.12 rock 5

3 176.16.1.44 176.16.1.12 s. 2

---

Frame at receiver

Seq No Dest Src Data Length

---------------------------------------------------------------------------------------

3 176.16.1.44 176.16.1.12 s. 2

1 176.16.1.44 176.16.1.12 e boy 5

0 176.16.1.44 176.16.1.12 Mysor 5

2 176.16.1.44 176.16.1.12 rock 5

Information received at reciever

s.e boyMysor rock

---

Frames at receiver after sorting

Seq No Dest Src Data Length

---------------------------------------------------------------------------------------

0 176.16.1.44 176.16.1.12 Mysor 5

1 176.16.1.44 176.16.1.12 e boy 5

2 176.16.1.44 176.16.1.12 rock 5

3 176.16.1.44 176.16.1.12 s. 2

Information at receiver after sorting

Mysore boy rocks.

Frame Sorting Technique used in buffer.

#include

struct frame{

int num;

char str[20];

};

struct frame arr[10];

int n;

void sort() /*Bubble sort */

{

int i,j;

struct frame temp;

for(i=0;i

for(j=0;j

if(arr[j].num>arr[j+1].num)

{ temp=arr[j];

arr[j]=arr[j+1];

arr[j+1]=temp;

}

}

int main()

{

int i;

system("clear");

printf("Enter the number of frames\n");

scanf("%d",&n);

printf("Enter the frame sequence number and frame contents\n");

for(i=0;i

scanf("%d%s",&arr[i].num,&arr[i].str);

sort();

printf("The frame in sequences\n");

for(i=0;i

printf("%d\t%s\n",arr[i].num,arr[i].str);

}

Mr. Gauro

Nepal Engineering and Technical Science Academy

Birendranagar, Surkhet

Nepal

User Avatar

Wiki User

13y ago
User Avatar

Add your answer:

Earn +20 pts
Q: Frame Sorting Program using C
Write your answer...
Submit
Still have questions?
magnify glass
imp