math_client.c

来自「linux 高级编程的例子源码,包括了本书上的所有代码」· C语言 代码 · 共 89 行

C
89
字号
/* * 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 "math.h"voidmath_prog_2(char *host){	CLIENT *clnt;	struct MATH  *result_1;	struct MATH  math_proc_2_arg;    char c;

	printf("Input The Machinename:");
    scanf("%s",name);
	printf("Input The UserID:");
	scanf("%d",&uid);
	printf("Input The GroupID:");
	scanf("%d",&gid);
        getchar();
	printf("choose the operation:\n\t0---ADD\n\t1---SUB\n\t2---MUL\n\t3---DIV\n");

    c=getchar();
    switch ( c )
    {
      case '0':
         math_proc_2_arg.op=ADD;
         break;
      case '1':
         math_proc_2_arg.op=SUB;
         break;
      case '2':
         math_proc_2_arg.op=MUL;
         break;
      case '3':
         math_proc_2_arg.op=DIV;
         break;
      default :
         printf("error :operation\n");
         exit(1);
    }
   
    printf("Input the first number: ");
    scanf("%f",&math_proc_2_arg.arg1);
   
    printf("Input the second number: ");
    scanf("%f",&math_proc_2_arg.arg2);
#ifndef	DEBUG	clnt = clnt_create (host, MATH_PROG, MATH_VER, "udp");	if (clnt == NULL) {		clnt_pcreateerror (host);		exit (1);	}#endif	/* DEBUG */	result_1 = math_proc_2(&math_proc_2_arg, clnt);	if (result_1 == (struct MATH *) NULL) {		clnt_perror (clnt, "call failed");	}#ifndef	DEBUG	clnt_destroy (clnt);#endif	 /* DEBUG */

	printf("The Result is %.3f \n",result_1->result);
}intmain (int argc, char *argv[]){	char *host;	if (argc < 2) {		printf ("usage: %s server_host\n", argv[0]);		exit (1);	}
	host = argv[1];	math_prog_2 (host);    exit (0);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?