| | |
How to send a double value in socket programming
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2005
Posts: 13
Reputation:
Solved Threads: 0
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....
<< moderator edit: added [code][/code] tags >>
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....
C Syntax (Toggle Plain Text)
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);
C Syntax (Toggle Plain Text)
double a=123.456; char msg1[3]; sprintf(msg1,"%g",a);
send(sockfd2,msg1,sizeof(msg1),0); "One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- Socket Programming... (C#)
- About socket programming in php (PHP)
- How to send messages in C++ (C++)
- C++ socket programming (C++)
- Problem with Client-Server Socket Connection (Java)
- Socket programming + porting Unix to Win32 (C)
Other Threads in the C Forum
- Previous Thread: how to find all the drives on a computer?
- Next Thread: Implement "Whats This" using Win32
| Thread Tools | Search this Thread |
adobe ansi api array arrays asterisks binarysearch calculate centimeter char convert copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax directory dynamic fflush file fork forloop frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop initialization interest kernel km linked linkedlist linux linuxsegmentationfault list lists locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix power problem probleminc program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socketprograming stack standard string strings structures systemcall testautomation turboc unix user variable voidmain() wab win32api windows.h






