Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <unistd.h>
- using namespace std;
- int count_occurrences(int num, int arr_size, int arr[]);
- int main()
- {
- //set up random integer array
- int array_size = 1000;
- int array[array_size];
- for (int i=0; i<array_size; i++)
- {
- array[i] = rand() % 101;
- }
- //instead of reading in input file, just add this array
- int nums_to_check[19] = {5,13,24,6,17,20,1,51,36,42,2,19,67,35,64,91,96,84,72};
- //stream through the input file
- for (int i=0; i<19; i++)
- {
- int num_occ;
- int fork_check;
- //fork child process
- fork_check = fork();
- // check if it is child process
- if (fork_check == 0)
- {
- num_occ = count_occurrences(nums_to_check[i], 1000, array);
- cout << "query: " << a << "\tcount: " << num_occ << "\tPID: " << pid << endl;
- return 0;
- }
- return 0;
- }
- int count_occurences(int num, int arr_size, int arr[])
- {
- int count = 0;
- for (int i=0; i<arr_size; i++)
- {
- if (arr[i] == num)
- {
- count += 1;
- }
- }
- return num;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement