⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 math_client.c

📁 linux 高级编程的例子源码,包括了本书上的所有代码
💻 C
字号:
/* * 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("choose the operate:\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 :operate\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);	}
    
	strcpy(hostname,argv[1]);
	host = argv[1];	math_prog_2 (host);    exit (0);}

⌨️ 快捷键说明

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