help with sprintf (i think)

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 78
Reputation: drjay1627 is an unknown quantity at this point 
Solved Threads: 1
drjay1627 drjay1627 is offline Offline
Junior Poster in Training

help with sprintf (i think)

 
0
  #1
Apr 24th, 2009
I doing this server and client program. The sever has to output to the client.
  1. strcpy ( outBuf, " " );
  2. sprintf ( outBuf, "cylinder: %d Sector: %d\n", cylinders, sectors );
  3. if ( write ( client_sockfd, outBuf, strlen ( outBuf ) + 1 ) < 0 ) {
  4.  
  5. perror ( "Client: Fails to write to socket." );
  6.  
  7. exit ( 3 );
  8.  
  9. }
I cout outBuf to server:

outBuf: cylinder: 5 Sector: 5

at the client end:
> I -- this is input
cylinder: 5 Sector: --this is all that gets printed.
> enter I again and hit enter
5
>

as you can see when i hit return, then the rest of the stream gets printed. can someone help me fix this]?

thanks

drjay
the when i hit enter again, the 5 gets printed.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: help with sprintf (i think)

 
0
  #2
Apr 24th, 2009
I don't get your question ...
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 78
Reputation: drjay1627 is an unknown quantity at this point 
Solved Threads: 1
drjay1627 drjay1627 is offline Offline
Junior Poster in Training

Re: help with sprintf (i think)

 
0
  #3
Apr 24th, 2009
when the sever out put to the client, how do i get the whole stream rather than just part of it?
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: help with sprintf (i think)

 
0
  #4
Apr 24th, 2009
I can't see the link with sprintf , but if you want to know more about it, just google on it (e.g.:http://www.cplusplus.com/reference/c...stdio/sprintf/) ...

Edit:: What do you mean with "sever", it's an English verb, but I think you meant the noun "server" ...
Last edited by tux4life; Apr 24th, 2009 at 4:57 pm.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 78
Reputation: drjay1627 is an unknown quantity at this point 
Solved Threads: 1
drjay1627 drjay1627 is offline Offline
Junior Poster in Training

Re: help with sprintf (i think)

 
0
  #5
Apr 24th, 2009
its server not sever... that was a typo.

char outBuf[128];
int cylinders, sectors, client_sockfd;
sprintf ( outBuf, "cylinder: %d Sector: %d\n", cylinders, sectors );
write ( client_sockfd, outBuf, strlen ( outBuf ) + 1 )

This doesn't write the entire outBuf to the client's screen.

How question is how do I to fix it? anyone???
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: help with sprintf (i think)

 
0
  #6
Apr 25th, 2009
Can you please provide me with some more information about what your program actually does ?
Last edited by tux4life; Apr 25th, 2009 at 7:41 am.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 78
Reputation: drjay1627 is an unknown quantity at this point 
Solved Threads: 1
drjay1627 drjay1627 is offline Offline
Junior Poster in Training

Re: help with sprintf (i think)

 
1
  #7
Apr 25th, 2009
I actually fixed it. The fault was at the client end. worked on it for about 5 hours!

The read function in the client read in a char array of a fixed size. when the write from the server is bigger than that, it didnt display the whole thing.

I thought it was something wrong with at the server end and tried a million things. eventually i gave up and move on to implementing other requirements and while fixing something else i found out that bug!

thanks you all your responses...

drjay
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC