1、#include#includeclient()int i=0;char ch,a20,c;FILE *fp1,*fp2;textcolor(3);clrscr();printf(“Receive:n“);fp1=fopen(“c:server1.txt“,“rb“);ch=fgetc(fp1);fp2=fopen(“c:num1.txt“,“rb“);while(ch!=nif(c=0)printf(“send againn“);elseif(c=1)printf(“%c“,ch);printf(“tsuccessn“);ch=fgetc(fp1);sleep(2); fclose(fp1)
2、;fclose(fp2); main() client();printf(“Please any key.“);getchar();#include#includeserver()int i,t;char ch,a20,c;FILE *fp1,*fp2,*fp3,*fp4;textcolor(2);clrscr();i=0;t=0;printf(“Sent a message:n“);fp1=fopen(“c:server.txt“,“wb“); /*存要发送的数据 */fp3=fopen(“c:server1.txt“,“wb“);ch=getchar();fputc(ch,fp1);fpu
3、tc(ch,fp3);while(ch!=n)ch=getchar();fputc(ch,fp1);fputc(ch,fp3);fclose(fp1);fclose(fp3);fp2=fopen(“c:num.txt“,“wb“);fp4=fopen(“c:num1.txt“,“wb“);for(i=0;i30;i+)t=rand()%2;if(t=0)c=0;fputc(c,fp2);fputc(c,fp4);elseif(t=1)c=1;fputc(c,fp2); fputc(c,fp4);fclose(fp2);fclose(fp4);fp1=fopen(“c:server.txt“,“rb“); /*开始发送信息*/ch=fgetc(fp1);fp2=fopen(“c:num.txt“,“rb“);c=fgetc(fp2);while(ch!=n)printf(“%c“,ch);ai=ch;if(c=1) printf(“ttACK“);i+;ch=fgetc(fp1);elsech=ai;c=fgetc(fp2);printf(“n“);sleep(2);fclose(fp1);fclose(fp2); main()server();printf(“Please any key.“);getchar();