Advertisement
STANAANDREY

strtok_r example

Jul 22nd, 2024
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main() {
  6.     char s[] = "alall kdgk ijr rijw,, rjgf. dd";
  7.     const char *delim = " ,.";
  8.     char *saveptr;
  9.  
  10.     for (char *token = strtok_r(strdup(s), delim, &saveptr); token; token = strtok_r(NULL, delim, &saveptr)) {
  11.         puts(token);
  12.     }
  13.  
  14.     puts(s);
  15.     return 0;
  16. }
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement