Hello everybody... I'm new in this forum , and sorry if my english isn't very good!
I must create a client server application... and my problem is:
when the client connects to the server the first time, he has to register with a user name and a password! The client sends username and password in a buffer in this mode:
username/password/
now in the server I must to divide this string into
username
password
I tried with a for cycle and with a while but it doesn't work...
Please help me:(!! Thank very much!!
If you're free to modify the buffer:
char buf[]="username/password/";
char *username=strtok(buf, "/");
char *pass=strtok(NULL, "/");
printf("username %s password %s\n", username, pass);
Just be careful not to use strtok() in a multithreaded app if you're not absolutely sure what's going on inside your app.. The strtok() call is NOT multithread-safe.
There is a thread-safe variant(strtok_r) but afaik only GNU/Linux has it, along with a handful of thread-safe variants of other common things. They use pointer pointers to safely keep their persistent data in user-defined space.
strtok_r() has been derived from the Pthreads standard (aka IEEE Std 1003.1c-1995) and has been present since SUSv2 (1997)...
Cheers,
Lo�c
Sorry but if I must divide 1 string into three string with strtok()???
Like in this example:
Destination/Object/Text/
Destination
Object
Text
Thank everybody!
---------- Post updated at 04:22 PM ---------- Previous update was at 02:03 PM ----------
I solved it!