client.c:60:17: warning: format '%d' expects argument of type 'int', but argument 2 has type 'int *' [-Wformat]
client.c:63:17: warning: format '%d' expects argument of type 'int', but argument 2 has type 'int *' [-Wformat]
下,這是代碼解決這個錯誤:請誰可以幫我在UNIX
#include <stdio.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc , char ** argv)
{
if(argc != 3) //check for parameters
{
printf("usage : a.out <IP=127.0.0.1> <Port number=22033>\n");
return 0;
}
//int x;
int sockfd , port = 0 ;
int intger[101] , buff[101];
struct sockaddr_in servaddr;
port = atoi(argv[2]); //convert port number from string to integer
bzero(&servaddr,sizeof(servaddr)); //reset the servaddr
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(port);
inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
sockfd = socket(AF_INET, SOCK_STREAM, 0); //new socket
bzero(buff,101); //reset the buffer
bzero(intger,101); //
connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)); //connect to the server
bzero(buff,101); //reset the buffer
//for(;;){
printf("Please Enter an Integer :");
scanf("%d", intger); //reading from the user
write(sockfd , intger , 300); //sending the integer to the server
printf("Sending %d to the server\n" , intger);
printf("Waiting for server reply ...\n");
read(sockfd , buff , 300);
printf("Received %d from the server\n" , buff);
//bzero(buff,300);
printf("\n");
//}
return 0;
}
請張貼您的代碼。 –
John Kugelman我已經下載了代碼 – joys