








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
error detection codes in Computer Networks
Typology: Study notes
1 / 14
This page cannot be seen from the preview
Don't miss anything!









int choice; while(1) { printf("\n1.Find CRC\t2.Check CRC\t3.Exit \nYour choice\t"); scanf("%d",&choice); switch(choice) { case 1: printf("Enter the input string\n"); scanf("%s",text); printf("Enter the key\n"); scanf("%s",key); crc(); printf("the transmitted message is %s\n",strcat(text,rem)); break; case 2: printf("Enter the input string\n"); scanf("%s",&text); printf("Enter the key\n"); scanf("%s",key); crc(); for(i=0;i<strlen(key)-1;i++) if(rem[i]=='1') break; if(i==strlen(key)-1) printf("There is no error in the message\n"); else printf("There is error in the message\n"); break; case 3: exit(0); } } }
Aim: To CheckSum using C language: Code: #include<stdio.h> #include<math.h> void sender() { printf("Sender:\n\n"); int a[10],i,m,scheck,rcheck; printf("Enter number of data segments: "); scanf("%d",&m); printf("Enter the data segments:\n"); for(i=0;i<m;i++) scanf("%d",&a[i]); int checksum,sum=0; for(i=0;i<m;i++) sum+=a[i]; checksum=~sum; printf("Checksum: %d\n",checksum); } void receiver() { printf("Reciever:\n\n"); int a[10],i,m,scheck; printf("Enter number of data segments: "); scanf("%d",&m); printf("Enter the data segments:\n"); for(i=0;i<m;i++) scanf("%d",&a[i]); printf("Enter the recieved checksum: "); scanf("%d",&scheck); int checksum,sum=0; for(i=0;i<m;i++) sum+=a[i]; sum=sum+scheck;
checksum=~sum; printf("Checksum: %d\n", checksum); if(checksum==0) printf("No error in transmission\n"); else printf("Error in transmission\n"); } int main() { int a; while(1) { printf("Enter 1 for sender and 2 for reciever. Press 3 to quit\n"); scanf("%d",&a); if(a == 1) sender(); else if(a == 2) receiver(); else if(a == 3) break; else printf("Invalid choice\n"); } return 0; }