我必須將fgets
的輸出連接到int
(clientid
),並將其存儲在char[1024]
緩衝區中。String and int concatination
這裏是我的代碼:
clientid = rand() % 256;
while(1)
{
cout<<"Client: Enter Data for Client=";
fgets(buffer,MAXSIZE-1,stdin);
if((send(sockfd,buffer,strlen(buffer),0))==-1)
{
cout<<"Failure Sending Message";
close(sockfd);
exit(1);
}
else
{
cout<<"Client:Message being sent:"<<buffer;
num=recv(sockfd,buffer,sizeof(buffer),0);
if(num<=0)
{
cout<<"either connection close or Error";
break;
}
buffer[num]='\0';
cout<<"Client:message received from Server:"<<buffer<<endl;
}
}
close(sockfd);
return 0;
我怎樣才能提取clientid
從服務器端的消息?
一個建議開始使用的std :: string ......一定會節省大量的精力 – HadeS