Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
19 views3 pages

SNW Receiver

snw

Uploaded by

Arnab Dhara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

SNW Receiver

snw

Uploaded by

Arnab Dhara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

//Receiver.

#include<stdio.h>

#include<conio.h>

#include<string.h>

int main()

int n;

int i,j,keylen=5,msglen=8,count;

char input[100], key[30]={'1','1','0','0','1'},temp[30],quot[100],rem[30],key1[30],input1[100];

FILE *data;

FILE *ack;

strcpy(key1,key);

while(1)

int one=0;

data=fopen("data.txt", "r+");

fscanf(data, "%s", input);

n = strlen(input);

printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nChecking CRC");

for (i=0;i<keylen;i++)

temp[i]=input[i];

for (i=0;i<msglen;i++) {

quot[i]=temp[0];

if(quot[i]=='0')

for (j=0;j<keylen;j++)

key[j]='0'; else

for (j=0;j<keylen;j++)

key[j]=key1[j];

for (j=keylen-1;j>0;j--) {

if(temp[j]==key[j])

rem[j-1]='0'; else

rem[j-1]='1';
}

rem[keylen-1]=input[i+keylen];

strcpy(temp,rem);

strcpy(rem,temp);

printf("\nRemainder is ");

for (i=0;i<keylen-1;i++)

printf("%c",rem[i]);

printf("\nRetrieved data is: ");

for (i=0;i<msglen;i++)

printf("%c",input[i]);

for(i=0;i<strlen(input);i++)

count=0;

for(j=i;j<(i+5);j++)

if(input[j]=='1')

count++;

if(count==5)

for(j=i+6;j<strlen(input);j++)

input[j-1]=input[j];

i=i+5;

printf("\nOuput of destuffing is: %s",input);

for (i=0;i<keylen-1;i++){

if(rem[i]=='1')

one++;
}

ack =fopen("ack.txt", "w+");

if(one>0){

printf("\nReminder is not zero and NACK generated\n\n");

fprintf(ack, "0");}

if(one==0){

printf("\nReminder is zero and ACK generated\n\n");

fprintf(ack, "1");}

fclose(data);

fclose(ack);

getch();

You might also like