クライアントからサーバーに送信するときに、出力ファイルに奇妙な文字がたくさんあります。サーバーを配列にストリームしてプリントアウトすると、見た目がよく見えるようになります。しかし、私はそれをサーバーに送ると、テキスト文書のいたるところに奇妙な文字とMICROSOFTがたくさんあります。誰が間違っているのか分かっていますか?サーバー側で奇妙な文字が出力される
クライアント:
if(sendSize <=0){
for(;;){
unsignedchar buff[256]={0};
int nread = fread(buff,1,256, fp);
total = total + nread;
percentage =(total/fFileSize)*100;
printf("\r%s: Percentage sent: %.2f", NAME_C, percentage);
/* Send data in 256 byte chunks */
if(nread >0){
send(clientSock, buff, nread, 0);
}
if(nread <256){
if(feof(fp)){
printf("\nSend Success!\n");
break;
}
}
}
//printf("%.2f", total);
}
サーバー:それは代わりに>0
を使用しなければならないとき
/* Receive data from client */
char* fileName ="test.txt";
FILE*fp = fopen(fileName,"w+");;
float total =0;
float bytesReceived;
unsignedchar buff[256]={0};
float percentage =(bytesReceived/total)*100;
while((bytesReceived = recv(listenSock, buff,sizeof(buff),0))<0){
//bytesReceived = recv(listenSock, buff, 256, 0);
if(bytesReceived >0){
printf("DONE");
}
//total = total + bytesReceived;
fwrite(buff,sizeof(char), bytesReceived, fp);
//printf("\r%s: Percentage received: %.2f", NAME_C, percentage);
}
'unsignedchar'である何よりの代わりにこのような何かを試してみてください? – Barmar
2つのシステムではどのオペレーティングシステムを使用していますか?いずれかがWindowsの場合は、テキストファイルでない場合はファイルを開くときにバイナリモードを使用する必要があります。 – Barmar
どうやってそれをしますか? –