Include error with # include <sys/wait.h>

27 Views Asked by At

so im working on a C program that implements collatz conjecture and my code seems to be fine on a friends desktop but on mine it gives me an include error for the include message#include <sys/wait.h>

this is the entire code here

# include <stdio.h>
# include <stdlib.h>
# include <unistd.h>
# include <sys/wait.h>

int main(int argc , char *argv[]) {
    if (argc < 2) {
        printf("please provide a number \n");
        return 1;
    }
     if (argc >2) {
        printf("please provide only 1 number \n");
        return 1;
    }

    int n = atoi(argv[1]);
    if (n <= 0) {
        printf("please provide a positive number\n");
        return 1;
    }

    int rc = fork();
    if (rc == 0) {
        while (n != 1) {
            if (n % 2 == 0) {
                n = n / 2;
            } else {
                n = 3 * n + 1;
            }
            printf("%d\n", n);
        }
    } else if (rc > 0) {
        wait(NULL);
    } else {
        printf("fork failed\n");
        return 1;
    }

    return 0;
}
0

There are 0 best solutions below