All pastes #834741 Raw Edit

Something

public text v1 · immutable
#834741 ·published 2007-12-28 12:50 UTC
rendered paste body
include <rpc/rpc.h> #include <stdio.h> #include "common.h" #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <dirent.h>

int *proc1 ();

int pow(int src,int p){ int i,rez=1; for(i=0;i<p;i++){ rez=rez*src; } return rez; }

int octtodec(int src){ int st=0,rez=0,i;

while(src!=0){ i=src%10; src=src/10; rez=rez+i*pow(8,st); st++; } return rez; }

main () { registerrpc (MY_PROG, MY_VER, MY_PROC1, proc1, xdr_wrapstring, xdr_int); svc_run(); fprintf (stderr, "Error: svc_run returned\n"); exit (1); }

int *proc1 (indata_p) char **indata_p; { static int res; static char odd[] = {"odd"}; char *s; int n,i; char otvet[100]; char one[10]="\0\0\0\0\0\0\0\0\0\0"; char two[10]="\0\0\0\0\0\0\0\0\0\0"; char z[3]="\0\0\0"; s=(*indata_p); // Выделяем первый аргумент n=strcspn(s,":"); strncpy(one,s,n); printf("->> %s\n",one); s = strpbrk(s,":"); // --- // Выделяем знак выражения z[0]=s[1]; printf("znak = %s\n",z); // --- // Выделяем вторый аргумент s=strpbrk(s,"|"); printf("strlen = %i n =%i str =%s\n",strlen(s),n,s); for(i=1;i<strlen(s);i++){ two[i-1]=s[i]; } printf("->> %s\n",two); // ---

n=atoi(one); i=atoi(two);

n=octtodec(n); i=octtodec(i);

if (strcmp(z,"+")==0){n=n+i;} if (strcmp(z,"-")==0){n=n-i;} if (strcmp(z,"*")==0){n=n*i;} if (strcmp(z,"/")==0){n=n/n;}

printf ("Result: %i\n", n); res=n; return &res; }