fork download
  1. #include <string.h>
  2. #include <stdio.h>
  3.  
  4. int main () {
  5. char str[80] = "A - B - C";
  6. char str2[80] = "D - E - F";
  7. const char s[2] = "-";
  8. char *token;
  9. char *token2;
  10.  
  11. /* 获取第一个子字符串 */
  12. token = strtok(str, s);
  13. token2 = strtok(str2, s);
  14.  
  15. /* 继续获取其他的子字符串 */
  16. while( token != NULL ) {
  17. printf( "%s\n", token );
  18. printf( "%s\n", token2 );
  19.  
  20. token = strtok(NULL, s);
  21. token2 = strtok(NULL, s);
  22. }
  23.  
  24. return(0);
  25. }
Success #stdin #stdout 0s 5264KB
stdin
Standard input is empty
stdout
A 
D 
 E 
 F