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.