#include <iostream>
#include <unistd.h>
using namespace std;
int main()
{
int fd[2];
//fd[0] - read
//fd[1] -write
//declare all the variables
int n;
int countN;
int arr[3];
//prompt for the numbers called n
//there are at most 3 nums(use countN to check)
while(countN <= 2){
cin >> n;
// checked whether the num is from range 1 to 15
if(n >= 1 && n <= 15)
{
//if yes, then push the num to array called arr
arr[countN] = n;
countN++;
}
else
{
//if no, then only increase the countN so that we dont cin more than 3 nums
countN++;
}
}
//print all the nums in the array named arr
for(int i = 0; i < 3; i++)
{
cout << arr[i];
}
//initializes fork
pid_t c_pid = fork();
//everything belows this gonna gets executed twice
return 0;
}
So, I am trying to initialize the fork system call, but then it has the error:
In function ‘int main()’: ‘fork’ was not declared in this scope. Can someone tell me what I have done wrong since I have check to make sure the fork initialization is not within any block like if or while loop.
I have even tried to declare it in the first line of the code(after main()), but it still has that error.