Guest User

Untitled

a guest
Dec 15th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int matchCount, findResult;
  8. long childPID;
  9. string userInput = "blank";
  10.  
  11. // string to be searched through
  12. string longString = "The PPSh-41 is a Soviet submachine gun designed by Georgi Shpagin as an inexpensive, simplified alternative to the PPD-40.";
  13.  
  14. while (userInput.compare("!wq"));
  15. {
  16. // reset variables for reuse
  17. matchCount = 0;
  18. findResult = -1;
  19.  
  20. cout << "Please enter a word/s to search for (!wq to exit): "; // prompts user for string to search for
  21. cin >> userInput; // takes user input
  22.  
  23. if (userInput.compare("!wq")) // checks user input to see if they still wish to search for a string
  24. {
  25. childPID = fork();
  26.  
  27. if (childPID == 0)
  28. {
  29. while (findResult < longString.length)
  30. {
  31. findResult = longString.find(userInput, findResult + 1, userInput.length);
  32.  
  33. if (findResult < longString.length)
  34. matchCount++;
  35. }
  36.  
  37. cout << "There are " << matchCount << " instances of " << userInput << " in longString." << endl;
  38. }
  39. else
  40. cout << "childPID != 0" << endl;
  41. }
  42. else
  43. cout << "User has chosen to exit. Exiting." << endl;
  44. }
  45.  
  46. return 0;
  47. }
  48.  
  49. Project Properties -> C++ -> Precompiled Headers
  50.  
  51. #include <stdafx.h>
Add Comment
Please, Sign In to add comment