strtok_r.c 511 B

12345678910111213141516171819
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. int main(void) {
  5. char source[] = "I'd just like to interject for a moment. What you're referring to as Linux, "
  6. "is in fact, GNU/Linux, or as I've recently taken to calling it, GNU plus Linux.\n";
  7. char* sp;
  8. char* token = strtok_r(source, " ", &sp);
  9. while (token) {
  10. printf("%s", token);
  11. if ((token = strtok_r(NULL, " ", &sp))) {
  12. printf("_");
  13. }
  14. }
  15. return EXIT_SUCCESS;
  16. }