a53

ExtrageCuvant_PT

a53
Oct 23rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. int extrageCuvant(char dest[], char sir[], char separatori[], int pozitie)
  2. {
  3. int i=0;
  4. int contorCuvant=0;
  5. int k=0;
  6.  
  7. struct myStr { // struct's as good as class
  8. static int cautaLitera(char s[], char c)
  9. {
  10. for(int poz=0; s[poz]; poz++)
  11. if (s[poz]==c) return 1;
  12. return 0;
  13. }
  14. };
  15.  
  16. int lung=0;
  17. while (sir[lung++]);
  18.  
  19. while(sir[k] && contorCuvant<pozitie)
  20. {
  21. if (myStr::cautaLitera(separatori, sir[k])) while (myStr::cautaLitera(separatori, sir[k])) k++;
  22. while (!myStr::cautaLitera(separatori, sir[k]))k++;
  23. contorCuvant++;
  24. }
  25. if (k>lung) return 0;
  26. if (myStr::cautaLitera(separatori, sir[k])) while (myStr::cautaLitera(separatori, sir[k])) k++;
  27. if (k>lung) return 0;
  28. while (sir[k])
  29. {
  30. dest[i]=sir[k];
  31. i++;
  32. k++;
  33. if (myStr::cautaLitera(separatori, sir[k]) || k==lung) break;
  34. }
  35. dest[i]=0;
  36.  
  37. if (dest[0]) return 1;
  38. return 0;
  39. }
Add Comment
Please, Sign In to add comment