-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSlidingwindow.c
33 lines (32 loc) · 1 KB
/
Slidingwindow.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<stdio.h>
#include<stdlib.h>
int main(){
int w,f,*frames;
printf("Enter size of sliding window:");
scanf("%d",&w);
printf("Enter no.of frames:");
scanf("%d",&f);
if(w <= 0 || f <= 0){
printf("Invalied inputs.");
return 1;
}
frames = (int*)malloc(f * sizeof(int));
printf("Enter %d frames:",f);
for(int i = 0;i < f;i++){
scanf("%d",&frames[i]);
}
printf("----\nThefollowing is by using Sliding windoew protocol\n----\nSender: ");
for(int i = 0;i < f;i++){
if((i+1)%w==0){
printf("%d ",frames[i]);
printf("\nAcknowledgement recieved");
printf("\nSender: ");
}else{
printf("%d ",frames[i]);
}
}
if(f%w != 0){
printf("\nAcknowledgement recieved\n");
}free(frames);
return 0;
}