c - Simple calculator with rpcgen -
i new in programming in c. try create small , simple program addition of 2 integers file calculs.x
here, contents of file calculs.x
/* calculs.x*/ struct data_in { int arg1; int arg2; }; typedef struct data_in data_in; struct result_int { int result; int errno; }; struct result_float { int result; int errno; }; typedef struct result_int result_int; typedef struct result_float result_float; program calculs{ version version_un{ void calculs_null(void) = 0; result_int add (data_in) = 1; result_int sub(data_in) = 2; result_int mul(data_in) = 3; result_float div (data_in) = 4; } = 1; } = 0x20000001;
for first time, created file calculs.c client:
#include <rpc/rpc.h> #include "calculs.h" int main(int argc, char *argv[]) { int buffer[256]; struct data_in input; struct result_int *output; client *cl; if (argc != 2) { printf("usage: client hostname_of_server\n"); exit(1); } /*etablir le lien vers le serveur distant * cl = clnt_create(server, prog, vers, prot); */ cl = clnt_create(argv[1], calculs, version_un, "tcp"); if (cl == null) { clnt_pcreateerror(argv[1]); exit(1); } input.arg1 = 5; input.arg2 = 5; output = add_1(&input, cl); if (output == null) { clnt_perror(cl, argv[1]); exit(1); } printf("the result field %d\n", output->result); printf("the errno field %d\n", output->errno); clnt_destroy(cl); return 0; }
i have not received error compiling file, rcalculs.c file, can not compile. here file contents rcalculs.c:
#include <rpc/rpc.h> #include "calculs.h" result_int *add_1(struct data_in data, struct svc_req *rqstp) { int buffer; struct result_int result; int = data.arg1; int b = data.arg2; buffer = a+b; result.result = buffer; result.errno =0; return result; }
the message error compiling is
rcalculs.c:11:13: erreur: conflicting types ‘add_1’ in file included rcalculs.c:9:0: calculs.h:46:22: note: previous declaration of ‘add_1’ here rcalculs.c: in function ‘add_1’: rcalculs.c:19:5: erreur: incompatible types when returning type ‘struct result_int’ ‘struct result_int *’ expected
could me resolve problem, please?
erreur: conflicting types ‘add_1
this error because did not declare add_1() function. , when ever made function call add_1() treats declaration.
add line before main()
result_int *add_1(struct data_in data, struct svc_req *rqstp);
rcalculs.c:19:5: erreur: incompatible types when returning type ‘struct result_int’ ‘struct result_int *’ expected
result_int * add_1(struct data_in data, struct svc_req *rqstp) { int buffer; struct result_int result; //here declare pointer int = data.arg1; int b = data.arg2; buffer = a+b; result.result = buffer; //change here result.errno =0; //change here return result; //here returning struct result_int type required struct result_int * type }
return pointer. , changes accordingly in function.
output = add_1(&input, cl); //here passing reference of input need pass input.
Comments
Post a Comment