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.
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; 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. #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
Write and run a client and a server program in C-language using UDP
For program in C language: http://wiki.answers.com/Q/Program_to_print_sorting_of_an_array_in_clanguage&updated=1&waNoAnsSet=2 Program in C++: #include #include void main() { int i,j,n,t,a[50]; clrscr(); cout"%d",&n; cout
write a c++ program to convert binary number to decimal number by using while statement
yes
The standard library sort algorithm automatically uses MSD radix to sort strings: std::vector<std::string> vs = {"a", "b", "c" "d", "ab"}; std::sort(vs.begin(), vs.end()); After sorting, the order will be: {"a", "ab", "b", "c", "d"}
plz as soon as possible give me the program for shorting an array in asscending order without using any sort function in c++
C program for sorting the numbers is very basic, start writing it and if you are having problems, post your program here and a description of the problem and you will be helped. If you are taking a computer course, how do you expect to pass exams if you have plagiarized someone else work for your assignments.
C program for comparison of dates using structures
Write and run a client and a server program in C-language using UDP
For program in C language: http://wiki.answers.com/Q/Program_to_print_sorting_of_an_array_in_clanguage&updated=1&waNoAnsSet=2 Program in C++: #include #include void main() { int i,j,n,t,a[50]; clrscr(); cout"%d",&n; cout
Exactly what do you mean by 'C program in Java'
"C" is a programming language. It is implemented by writing a program using the C syntax and then translated by a compiler, which is an application program.
C does not support superclassing. Try C++.
Answer1. When you save file using extension ".c" the program executes using "C" compiler and it cannot execute any other program which is not in "C".So, we cannot execute program in "C" which is not in "C".2. When you save file using extension ".cpp" the program executes using "C++" compiler and it can execute program of "C" but it should be saved with extension ".cpp".So, There is a program which is not in "C++" can be executed in "C++" compiler.Another answerYour question is ambiguous. 1. Okay in C++ but not in C:int main (void){ cout
write a c++ program to convert binary number to decimal number by using while statement
You can debug C programs using gdb on Unix.
C programs do not function without functions.