| | |
help with sprintf (i think)
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2008
Posts: 78
Reputation:
Solved Threads: 1
I doing this server and client program. The sever has to output to the client.
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.
C++ Syntax (Toggle Plain Text)
strcpy ( outBuf, " " ); sprintf ( outBuf, "cylinder: %d Sector: %d\n", cylinders, sectors ); if ( write ( client_sockfd, outBuf, strlen ( outBuf ) + 1 ) < 0 ) { perror ( "Client: Fails to write to socket." ); exit ( 3 ); }
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.
I can't see the link with
...
Edit:: What do you mean with "sever", it's an English verb, but I think you meant the noun "server"
...
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."
•
•
Join Date: Nov 2008
Posts: 78
Reputation:
Solved Threads: 1
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???
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???
•
•
Join Date: Nov 2008
Posts: 78
Reputation:
Solved Threads: 1
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
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
![]() |
Similar Threads
- multiple sprintf = incorrect string? (C++)
- Problem understanding Sprintf (C++)
- Sprintf and buffer overflow (C)
- Is there a stream class member equivalent to sprintf() (C)
Other Threads in the C++ Forum
- Previous Thread: User Authentication
- Next Thread: get data from child process through pipe
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream input int integer java lib linux list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






