Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
531 B
1
Indexable
Never
// STOP AND WAIT PROTOCOL

#include <stdio.h>
#include <conio.h>  
#include <stdlib.h>
#include <string.h>

int main() {
    char s[1001];
    scanf("%s", s);
    int t = 5, seq = 0, i, r;
    for(i = 0; i < strlen(s); i++) {
        printf("Packet sent = %c with sequence number = %d\n", s[i], seq);
        r = rand() % 10;
        printf("Random value = %d\n", r);
        if(r > t) {
            printf("Not sent\n");
            i--;
        }
        else{
            seq = (seq == 0) ? 1:0;
        }
    }
    return 0;
}