Bonjour à tous,

je tente de faire un programme qui crée deux fils. Le premier fils demanderait 2 nombres à l'utilisateur puis le second fils calculerait R = n1 * n2.


Voici mon code:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
int tube[2];  //Les consignes m'obligent à déclarer en global...
int tube2[2];
 
void fctfils1(void)
{
	int nombre[2];
	printf("Insérez le premier nombre:");
	scanf("%d",&nombre[0]);
	printf("Insérez le deuxième nombre:");
	scanf("%d",&nombre[1]);
	close(tube[0]); 	                               
	write(tube[1],nombre,sizeof(nombre));          
	exit(0);
}
 
void fctfils2(void)
{
	int receptionNb[2];                  
	close(tube[1]);                         			 
	read(tube[0],receptionNb,sizeof(receptionNb));
	printf("le fils recoit: %d et %d\n", receptionNb[0], receptionNb[1]);
	int multi = receptionNb[0] * receptionNb[1];
 
	close(tube2[0]);
	write(tube2[1],multi,sizeof(multi));
	exit(0);
}
 
 
void fctpere(void)
{
	int multi;                  
	close(tube2[1]);                         	
	read(tube2[0],multi,sizeof(multi));
	printf("le père recoit: %d\n", multi); 				
	wait(0);
	wait(0);
	exit(0);
}
 
int main (int argc, char * argv[])
{
 
    if (((pipe(tube))<0) | ((pipe(tube2))<0)) exit(1);	
 
    pid_t pid = 1;
 
	if ((pid = fork()) < 0) exit(1);					
	if (pid == 0) fctfils1();				
 
	else{
		if ((pid = fork()) < 0) exit(1);				
		if (pid == 0) fctfils2();
		else fctpere();		
		}
 
}
J'obtiens un résultat extravagant...

Voici mes erreurs :

  • tube.c:34: warning: passing arg 2 of `write' makes pointer from integer without a cast
  • tube.c:43: warning: passing arg 2 of `read' makes pointer from integer without a cast


Aussi je ne parviens pas à utiliser un type double pour ma variable multi sans provoquer les erreurs:
  • tube.c:32: error: incompatible type for argument 2 of `write'
  • tube.c:41: error: incompatible type for argument 2 of `read'


Un immense merci pour votre aide...