1
您好每個人,這是擴展我以前question.Here是鏈接文件傳輸多餘的線條打印
我已經在我的文件名,併成功結束插入「/ N」檢索文件名以及文件中的數據。但有一些問題,經過我的服務器端從套接字讀取的字節數最多「/ N」也寫一個奇怪的說法在我的文件開始
ORBIT_SOCKETDIR =的/ tmp /軌道-CV
可以在任何一個告訴我發生了什麼事。如何避免它在我的文件存儲
這裏是我的代碼片段 client.c
char * filename = strrchr(argv[3],'/'); // extracting file name from path
*filename++; filename[strlen(filename)] = '\n'; // putting /n at the end of file name n = write(sockfd, filename, strlen(filename));
bzero(buffer,256); FILE *f = fopen("file.txt" ,"rb"); // opening the file
size_t bytes = 0;
// sending the actual data in the file
while((bytes = fread(buffer ,sizeof(char) ,sizeof(buffer) ,f))>0)
send(sockfd ,buffer ,bytes , 0);
server.c
while(ch[0] != '\n') // here reading the filename
{
n = read(newsockfd,ch,1);
filename[i] = ch[0];
printf("ch %c " , ch[0]);
i++;
}
FILE *f = fopen(filename ,"wb");
// reading the actual data and writing it in the file
while((bytes = recv(newsockfd ,buffer , sizeof(buffer) ,0))>0)
fwrite(buffer,sizeof(char) ,bytes , f);
但先生這是什麼意思是「ORBIT_SOCKETDIR =/tmp/orbit-cv」是因爲空? – mainajaved
@mainajaved:幾乎可以肯定,因爲缺少'NUL' ...你的字符串現在擴展到了它不應該存在的地方。 – NPE
非常感謝先生 – mainajaved