-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_client - Copie.c
108 lines (99 loc) · 2.44 KB
/
add_client - Copie.c
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* This is sample code generated by rpcgen.
* These are only templates and you can use them
* as a guideline for developing your own functions.
*/
#include "add.h"
void
add_prog_1(char *host, float x, float y, int op)
{
CLIENT *clnt;
float *result_1;
numbers add_1_arg;
float *result_2;
numbers sub_1_arg;
float *result_3;
numbers mul_1_arg;
float *result_4;
numbers div_1_arg;
add_1_arg.x = x;
add_1_arg.y = y;
sub_1_arg.x = x;
sub_1_arg.y = y;
mul_1_arg.x = x;
mul_1_arg.y = y;
div_1_arg.x = x;
div_1_arg.y = y;
#ifndef DEBUG
clnt = clnt_create (host, ADD_PROG, VERSION1, "udp");
if (clnt == NULL) {
clnt_pcreateerror (host);
exit (1);
}
#endif /* DEBUG */
switch(op){
case 1: {
result_1 = add_1(&add_1_arg, clnt);
if (result_1 == (float *) NULL) {
clnt_perror (clnt, "call failed");
}else{
printf("Resultat = %.2f\n", *result_1);
}
break;
}
case 2: {
result_2 = sub_1(&sub_1_arg, clnt);
if (result_2 == (float *) NULL) {
clnt_perror (clnt, "call failed");
}else{
printf("Resultat = %.2f\n", *result_2);
}
break;
}
case 3: {
result_3 = mul_1(&mul_1_arg, clnt);
if (result_3 == (float *) NULL) {
clnt_perror (clnt, "call failed");
}else{
printf("Resultat = %.2f\n", *result_3);
}
break;
}
case 4: {
result_4 = div_1(&div_1_arg, clnt);
if (result_4 == (float *) NULL) {
clnt_perror (clnt, "call failed");
}else{
printf("Resultat = %.2f\n", *result_4);
}
break;
}default:{
printf("Argument invalide!\n");
exit(-1);
}
}
#ifndef DEBUG
clnt_destroy (clnt);
#endif /* DEBUG */
}
int
main (int argc, char *argv[])
{
char *host;
int op;
if (argc < 3) {
printf ("Usage: %s server_host NUMBER NUMBER\n", argv[0]);
exit (1);
}
printf("==================================\n");
printf("\t\t1-Addition\n");
printf("\t\t2-Soustraction\n");
printf("\t\t3-Multiplication\n");
printf("\t\t4-Division\n");
printf("==================================\n");
printf("Choisir l'operation a faire: ");
scanf("%d",&op);
host = argv[1];
add_prog_1 (host, atof(argv[2]), atof(argv[3]), op);
exit (0);
}