fork(2) download
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4.  
  5. void output_w(FILE* _out, const char* s, const char* pfx){
  6. const char* p = s;
  7. const size_t n = strlen(pfx);
  8.  
  9. while((p = strstr(p, pfx)) != NULL){
  10. if((p == s) || ! isalpha(*(p - 1))){
  11. if(! strncmp(p, pfx, n)){
  12.  
  13. while(isalpha(*p))
  14. fputc(*p++, _out);
  15.  
  16. fputc('\n', _out);
  17. continue;
  18. }
  19. }
  20. p += n;
  21. }
  22. }
  23.  
  24. int main(void){
  25. char buf[64] = "hello, apply, apple, application, ap";
  26. char pfx[16] = "app";
  27. /*
  28. printf("Enter str: ");
  29. fgets(buf, sizeof(buf), stdin);
  30. printf("Enter prefix: ");
  31. scanf("%s", pfx);
  32. fflush(stdin);
  33. */
  34. output_w(stdout, buf, pfx);
  35. return 0;
  36. }
  37.  
  38.  
  39.  
Success #stdin #stdout 0s 2156KB
stdin
Standard input is empty
stdout
apply
apple
application