What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Copying part of a string

Copying part of a string
Author: Message:
Chancer
Senior Member
****

Avatar

Posts: 648
Reputation: 7
34 / Male / Flag
Joined: May 2005
Status: Away
O.P. Copying part of a string
I'm making a (rudimentary) chat system at college (server + client), and it works like this:

The user (using the client app) sends a string in the format COMMAND:text, ie, "USER:Chancer" changes my name to Chancer.

The problem is, it's one single string, and I need to read the text parameter alone.
I'm doing this:
C code:
for (k = 5; buffer[k - 1] != '\0'; k++)
    text[k - 5] = buffer[k];

buffer is the string sent by the user, k starts at 5 because all available commands are in the 4-char - colon pattern.
It's partially working, but I'm afraid the text vector is not receiving the '\0' character.

Previoulsy I had this, and it was OK:
C code:
for (k = 5; buffer[k] != '\0'; k++)
    text[k - 5] = buffer[k];
text[k - 6] = '\0';


But I just think it doesn't look good. I know that using "%.5s", for example, I can print 5 characters of a string. Is there anyway to print "from character 5 until the end (\0)"?

Edit:
Cool. I found a command "sscanf" which can split a string in many different strings in any pattern you choose.

This post was edited on 05-15-2011 at 05:06 PM by Chancer.
05-14-2011 08:46 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Copying part of a string - by Chancer on 05-14-2011 at 08:46 PM
RE: Copying part of a string - by Chancer on 05-15-2011 at 05:10 PM
RE: Copying part of a string - by Adeptus on 06-08-2011 at 05:49 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On