So in short, I have two .c files and a shared.h header file in the same directory.
This is shared.h:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string.h>
#include <fcntl.h>
#include <signal.h>
#include <errno.h>
// declaring the number to factor and the the variable
factor as shared gloval variables
extern int n;
extern int factor;
This is pfact.c:
#include "shared.h"
int n;
int factor = 0;
// start main
int main(int argc, char **argv) {
// fork
// if child, exec to child
return 0;
}
This is child.c:
#include "shared.h"
int main(){
int m=0, k;
int status, child_exit_status;
pid_t pid;
int fd[2]; //every child will create another pipe to write to in addition to the pipe it inherits from its parent to read from
printf("n is %d\n", n);
// goes more code
return 0
}
What am I doing wrong? the global variable n is declared once in pfact.c, "externed" in the header file shared.h and then the header file is included in child.c
Thanks in advance!