Results 1 to 3 of 3

Thread: [RESOLVED] Getting the length of a string of a buffer

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Resolved [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
    steve

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    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
  •  



Click Here to Expand Forum to Full Width