Hi all,
im new to this.....
i want to send a doube to client...so im convt that to char and sendg that...it prits d exact value in server, but in client it doesnt print the decimal value... it just display like '123.'
my code looks like....

struct sockaddr_in server; 
	struct sockaddr_in client; 
	int sockfd,sockfd2,sockfd3, n_bytes; 

	double a=123.456;
             char msg1[3];
	sprintf(msg1,"%g",a);    	
	    
	printf("\n msg1 = %s ",msg1);
//here it prints msg1=123.456 	  
	if((sockfd=socket(AF_INET,SOCK_STREAM,0))==-1)
	{ 
		printf("Socket error..."); 
		return 0; 
	} 

	server.sin_addr.s_addr=INADDR_ANY;  
	server.sin_port=htons(PORT);  
	server.sin_family=AF_INET; 
 
	send(sockfd2,msg1,sizeof(msg1),0);

<< moderator edit: added [code][/code] tags >>

Hello,

Moving to the C++ section for technical support / suggestion....

double a=123.456;
             char msg1[3];
	sprintf(msg1,"%g",a);

The string msg1 only has room for 2 characters and a terminating null. And you're trying to write 7 characters plus the null to it.

send(sockfd2,msg1,sizeof(msg1),0);

You might mean strlen(msg1).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.