fork download
  1. #define _DEFAULT_SOURCE
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7. char string[13];
  8. char *found, *cp = string;
  9.  
  10. fprintf(stderr, "\nEnter string: ");
  11. scanf("%12s",string);
  12. printf("Original string: '%s'\n",string);
  13.  
  14. while((found = strsep(&cp,"/,-")) != NULL )
  15. {
  16. printf("Test 1"); /*To pinpoint where the seg fault arises*/
  17. printf("%s\n",found);
  18. }
  19.  
  20. return(0);
  21. }
Success #stdin #stdout #stderr 0s 4308KB
stdin
aa/bb/cc/dd
stdout
Original string: 'aa/bb/cc/dd'
Test 1aa
Test 1bb
Test 1cc
Test 1dd
stderr
Enter string: