c - 2nd Call to strtok() returns null -


I am at the top of the loop in client file for client / server communication. I get user input (input) from client And I need to straddle in CMD and CMD 2 for the work of my IFS.

The user is said to be "find friend" (this is a good command for the program). Using the following code, CMD = "meet" (yay!), But CMD 2 = "(empty)"

input is a four input [30] CMD and CMD 2 letters start in four letters Are there.

A little help here? Thanks! / * As long as the user exits from the program / (Cmdnum! = 7) {printf ("\ nPlease enter a command:"); Scanf ("% 30s", input); CMD = Strontok (Input, ""); Printf ("CMD:% s \ n", CMD); If (SRCMP (CMD, "mill") == 0} {cmi2 = strotok (zero, "\ 0"); Printf ("cmd2:% s \ n", CMD2); Pstatus = Print (CMD, Sokfad); If (pstatus == 1) {printf ("printing print \ n"); }} And if (strcmp (cmd, "put") == 0) ..... etc, etc. ....

"\ 0" Think about it, it's just an empty string.

More importantly, you need to read in the entire line, which is scanf with % s Do not do this. It closes in the first place instead, try fgets But remember that it leaves the new line, so add it as a limit. #include int main () {four input [50]; printf ("Please enter an order Fgets (input, size input, stdin); four * CMD = string (input, "\ t \ n"); Printf ("CMD: [% s] \ n", CMD); SRCMP (CMD, "Receive") == 0} {char * cmd2 = strtok (NULL, "\ t \ n"); printf ("CMD 2: [% s] \ n", CMD2);} Return 0;}

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -