|
-
Oct 17th, 2007, 12:55 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Getting the length of a string of a buffer
Hello,
I have a buffer that contains words. However, the words comes from a client. I just want to get the words out. However, the buffer is being filled with rubbish after the words. Example "Manchester United&^&*#&#&##^&#@*&^^ etc.
How can I just get "Manchester United" out?
I have used the following using length and substring, but it displays everything
Code:
char buffer[256];
sock.receiveFrom(buffer,sizeof(buffer), addr);
std::string message = buffer;
int strLength = 0;
strLength = message.size();
std::cout << "The length of the string is: " << strLength << std::endl;
message = message.substr(0,strLength);
std::cout << message;
Many thanks,
Steve
-
Oct 17th, 2007, 08:14 AM
#2
Re: [RESOLVED] Getting the length of a string of a buffer
This is marked resolved with no posted solution.
Is it resolved?
If so, what did you do to resolve it? It might help someone else with a similiar problem.
-
Oct 22nd, 2007, 04:53 PM
#3
Re: [RESOLVED] Getting the length of a string of a buffer
If it's not resolved, it's up to the client to indicate the end of string. If it doesn't, there's no way a program can figure out where the end is on the fly.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|