Computer Networks Algorithms in C language

February 16, 2017 | Author: leelasaladi | Category: N/A
Share Embed Donate


Short Description

Download Computer Networks Algorithms in C language...

Description

Computer Networks Algorithms in C language Contents: 1. Bit Stuffing and Character Stuffing 2. CRC,CRC-12,CRC-16,CRC-CCIT 3. Dijkstra's Shotest path routing algorithm 4. Distance vector routing algorithm 5. Link state routing algorithm 6. Floding 7.Broadcasting 1.IMPLEMENTATION OF BIT STUFFING AND CHARACTER STUFFING #include #include #include main() { int ch; clrscr(); do { printf("\n********************:"); printf("\n1.BIT STUFFING:"); printf("\n2.CHARACTER STUFFING:"); printf("\n3.EXIT:"); printf("\n*********************"); printf("\nEnter your choice:"); scanf("%d",&ch); switch(ch) { case 1:bit(); break; case 2:character(); break; case 3:exit(0); } }while(ch!=3); getch(); } bit() { FILE *fp,*fp1; char ch; int i; if((fp=fopen("source.txt","w"))==NULL) { printf("\nError in opening the file"); exit(0); } printf("\nEnter data to send press 'e' to end :\n"); i=0; while(1) { scanf("%c",&ch); if(ch=='e') break; if(ch=='1') i++; else i=0;

putc(ch,fp); if(i==5) { putc('0',fp); i=0; } } fclose(fp); i=0; fp=fopen("source.txt","r"); fp1=fopen("dest.txt","w"); printf("\nDATA AFTER STUFFING\n"); while((ch=getc(fp))!=EOF) { putc(ch,stdout); } fseek(fp,0L,0); printf("\nDATA AFTER UNSTUFFING\n"); while((ch=getc(fp))!=EOF) { if(ch=='1') i++; else i=0; if(i==5) { putc(ch,stdout); putc(ch,fp1); ch=getc(fp); i=0; } else { putc(ch,stdout); putc(ch,fp1); } } fclose(fp); fclose(fp1); } character() { FILE *fp,*fp1; char ch,c[2],k[4],j[9]; long beg,end; if((fp=fopen("Input.txt","w"))==NULL) { printf("\n Input.txt file opening problem..."); exit(0); } printf("\nEnter data to send at end put '}': \n\n"); while(1) { scanf("%c",&ch); if(ch=='}') break; putc(ch,fp); }

fclose(fp); if((fp=fopen("Input.txt","r"))==NULL) { printf("\nInput.txt file opening problem..."); exit(0); } if((fp1=fopen("csource.txt","w"))==NULL) { printf("\ncsource.txt file opening problem..."); exit(0); } fputs(" DLE STX ",fp1); while((ch=getc(fp))!=EOF) { if(ch=='D') { c[0]=getc(fp); c[1]=getc(fp); if(c[0]=='L'&&c[1]=='E') fputs("DLE",fp1); putc(ch,fp1); putc(c[0],fp1); putc(c[1],fp1); } else putc(ch,fp1); } fputs(" DLE ETX ",fp1); fclose(fp); fclose(fp1); if((fp=fopen("csource.txt","r"))==NULL) { printf("\ncsource.txt file opening problem..."); exit(0); } if((fp1=fopen("cdest.txt","w"))==NULL) { printf("\ncdest.txt file opening problem..."); exit(0); } beg=ftell(fp); beg+=9; fseek(fp,-0L,2); end=ftell(fp); end-=9; fclose(fp); printf("\nData after stuffing "); fp=fopen("csource.txt","r"); while((ch=getc(fp))!=EOF) putc(ch,stdout); fclose(fp); printf("\n"); printf("\nThe data after destuffing"); fp=fopen("csource.txt","r"); fgets(j,9,fp); while(beg
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF