Implementation of Sliding Window C Program

Algorithm Steps:
Step 1: start the program.
Step 2: Open the input file in read mode.
Step 3: Read the size of the window
Step 4: Select randomly the number of packets is to be transferred.
Step 5: Read the content of the input file.
Step 6: Transfer the packet until it reaches the maximum defined size.
Step 7: Resume the window size and repeat the above two steps until packets in.
Step 8: Close the file.
Step 9: Stop the program.
#include<stdio.h>
#include<stdlib.h>
main()
int i,m,n,j,w,1;
char c;
FILE*f;
f=fopen("text.txt","r");
printf("window size");
scanf("%d",&n);
m=n;
while(!fof(f))
{
    i=rand()%n+1;
    j=i;
    1=i;
    if(m>i)
    {
        m=m-i;
        if(m>0)
        {
            printf("\n");
            while(i>0 & !feof(f))
            {
                c=getc(f);
                printf("%c",c);
                i--;
            }

            printf("\n%d transferred"j);

            if(j>3)
                printf("\n 1 acknowledgement received");
            else
                printf("\n acknowledgement received",j+1);
        }
    }
    m=m+j-1;
}
OUTPUT:
[csea56host csea56] cc slide07.c
[csea56host csea56]./a.out
window size3
we
2 transferred
ack received
1
1 transferred
ack received
co
2 transferred
ack received
me
3 transferred
ack received
1 transferred
ack received

Post a Comment

0 Comments