943,703 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 712
  • C++ RSS
Apr 24th, 2009
0

help with sprintf (i think)

Expand Post »
I doing this server and client program. The sever has to output to the client.
C++ Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 12
Solved Threads: 1
Junior Poster in Training
drjay1627 is offline Offline
87 posts
since Nov 2008
Apr 24th, 2009
0

Re: help with sprintf (i think)

I don't get your question ...
Reputation Points: 2125
Solved Threads: 243
Postaholic
tux4life is offline Offline
2,105 posts
since Feb 2009
Apr 24th, 2009
0

Re: help with sprintf (i think)

when the sever out put to the client, how do i get the whole stream rather than just part of it?
Reputation Points: 12
Solved Threads: 1
Junior Poster in Training
drjay1627 is offline Offline
87 posts
since Nov 2008
Apr 24th, 2009
0

Re: help with sprintf (i think)

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.
Reputation Points: 2125
Solved Threads: 243
Postaholic
tux4life is offline Offline
2,105 posts
since Feb 2009
Apr 24th, 2009
0

Re: help with sprintf (i think)

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???
Reputation Points: 12
Solved Threads: 1
Junior Poster in Training
drjay1627 is offline Offline
87 posts
since Nov 2008
Apr 25th, 2009
0

Re: help with sprintf (i think)

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.
Reputation Points: 2125
Solved Threads: 243
Postaholic
tux4life is offline Offline
2,105 posts
since Feb 2009
Apr 25th, 2009
1

Re: help with sprintf (i think)

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
Reputation Points: 12
Solved Threads: 1
Junior Poster in Training
drjay1627 is offline Offline
87 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: User Authentication
Next Thread in C++ Forum Timeline: get data from child process through pipe





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC