int radd( char* host, int a, int b ) { CLIENT *clnt; struct sockaddr_in timehost; int *result_1; clnt = clnt_create(host, ADDER, V1, "tcp"); if (clnt == NULL) { clnt_pcreateerror(host); exit(1); } timehost.sin_family = AF_INET; timehost.sin_addr.s_addr = htonl(INADDR_LOOPBACK); timehost.sin_port = htons(0); clnt->cl_auth = authdes_create("unix.500@homenet", 60, (struct sockaddr *) &timehost, (des_block *)NULL); /* Call the procedure twice to test nicknames */ result_1 = add_1(a, b, clnt); if (result_1 == NULL) { clnt_perror(clnt, "1st call failed:"); exit(1); } result_1 = add_1(a, b, clnt); if (result_1 == NULL) { clnt_perror(clnt, "2nd call failed:"); exit(1); } clnt_destroy( clnt ); return *result_1; }
void addition_1(char *host, int a, int b) { CLIENT *clnt; int *result_1; numbers add_1_arg; #ifndef DEBUG clnt = clnt_create (host, ADDITION, ADDITION_1, "udp"); if (clnt == NULL) { clnt_pcreateerror (host); exit (1); } #endif /* DEBUG */ //kot klienta przed add_1_arg.num1 = a; add_1_arg.num2 = b; result_1 = add_1(&add_1_arg, clnt); if (result_1 == (int *) NULL) { clnt_perror (clnt, "call failed"); } else { //kot klienta po printf("result: %d\n", *(int*)result_1); } #ifndef DEBUG clnt_destroy (clnt); #endif /* DEBUG */ }
void addition_1(char *host) { CLIENT *clnt; int *result_1; numbers add_1_arg; #ifndef DEBUG clnt = clnt_create (host, ADDITION, ADDITION_1, "udp"); if (clnt == NULL) { clnt_pcreateerror (host); exit (1); } #endif /* DEBUG */ scanf("%d",&add_1_arg.size); int i; for(i=0;i<add_1_arg.size;i++) { scanf("%d",&add_1_arg.nums[i]); } result_1 = add_1(&add_1_arg, clnt); if (result_1 == (int *) NULL) { clnt_perror (clnt, "call failed"); } printf("%d\n",*result_1); #ifndef DEBUG clnt_destroy (clnt); #endif /* DEBUG */ }
void add_prog_1(char *host) { CLIENT *clnt; int *result_1; intpair add_1_arg; #ifndef DEBUG clnt = clnt_create (host, ADD_PROG, ADD_VERS, "udp"); if (clnt == NULL) { clnt_pcreateerror (host); exit (1); } #endif /* DEBUG */ add_1_arg.a = 123; add_1_arg.b = 22; result_1 = add_1(&add_1_arg, clnt); if (result_1 == (int *) NULL) { clnt_perror (clnt, "call failed"); } else { printf("result = %d\n", *result_1); } #ifndef DEBUG clnt_destroy (clnt); #endif /* DEBUG */ }
int main(int argc, char **argv) { CLIENT *cl; add_in in; add_out *out; if (argc!=4) { printf("Usage: %s <machine> <int1> <int2>\n\n",argv[0]); return 1; } cl = clnt_create(argv[1], ADD_PROGRAM, ADD_VERSION, "tcp"); if (cl==NULL) { perror("Error creating RPC client!"); return 1; } in.arg1 = atol(argv[2]); in.arg2 = atol(argv[3]); out = add_1(&in, cl); if (out==NULL) { printf("Error: %s\n",clnt_sperror(cl,argv[1])); return 1; } else { printf("We received the result: %ld\n",*out); } return 0; }
void calccompprog_1(char *host) { CLIENT *clnt; int *result_1; complexe add_1_arg; int *result_2; complexe mul_1_arg; void *result_3; complexe init_1_arg; #ifndef DEBUG clnt = clnt_create (host, CALCCOMPPROG, CALCVERS, "udp"); if (clnt == NULL) { clnt_pcreateerror (host); exit (1); } #endif /* DEBUG */ add_1_arg.pentiere = 2; add_1_arg.pimaginaire = 0.5; result_1 = add_1(&add_1_arg, clnt); if (result_1 == (int *) NULL) { clnt_perror (clnt, "call failed"); } mul_1_arg.pentiere = 3; mul_1_arg.pimaginaire = 1.5; result_2 = mul_1(&mul_1_arg, clnt); if (result_2 == (int *) NULL) { clnt_perror (clnt, "call failed"); } init_1_arg.pentiere = 4; init_1_arg.pimaginaire = 2.5; result_3 = init_1(&init_1_arg, clnt); if (result_3 == (void *) NULL) { clnt_perror (clnt, "call failed"); } printf("ADD result : %d", *result_1); printf("MUL result : %d", *result_2); #ifndef DEBUG clnt_destroy (clnt); #endif /* DEBUG */ }
int main(void) { int iters; /* total iterations of the program */ int i; /* for for loop */ char line[1000001]; /* each individual case */ int len; /* length of caes */ scanf("%d", &iters); while (iters--) { scanf("%s", line); len = strlen(line); if ( number_like_9999(line, len) ) { /* checks to see if a number is only of the digit '9' *//* ex: 99999 returns 1 */ add_1(line, len); /* if the number is made only of the digit '9' then this function */ /* changes the string from a number like 999 to 1000 */ len++; } else { nine(line, len-1); //converts all ending '9' to '0' 1245[9][9] //len-1 cuz to access all array members // add 1 to the digit just before the ending '9' Ex : 1243[5]999 } for (i = 0; i < len/2; i++) { make_dec(line, i, len); } printf("%s\n", line); memset(line, 0, sizeof(line)); /* clean the array,initialise it to 0 for the next round */ } system("pause"); }
int main(int argc, char **argv) { CLIENT *cl; param in, *tmp; add_out *out; if (argc<4) { printf("Usage: %s <machine> <int1> <int2> <int3> ...\n\n", argv[0]); return 1; } cl = clnt_create(argv[1], ADD_PROG, ADD_VERS, "udp"); tmp = ∈ in.arg = strdup(argv[2]); printf("Arg: ***%s***\n",in.arg); argc -= 3; argv += 3; while (argc>0) { tmp->next = (struct param*) malloc(sizeof(struct param)); tmp = tmp->next; tmp->arg = strdup(argv[0]); printf("Arg: ***%s***\n",tmp->arg); argc--; argv++; } tmp->next = NULL; out = add_1(&in, cl); if (out==NULL) { printf("Error: %s\n",clnt_sperror(cl,argv[1])); } else { printf("We received the result: %d\n",*out); } return 0; }
void add_entry(CLIENT *c) { entry e; char name_array[NAME_SIZE], phone_array[PHONE_SIZE]; int *result; e.n = name_array; e.p = phone_array; read_string("Enter the name: ", e.n, NAME_SIZE); read_string("Enter the phone number: ", e.p, PHONE_SIZE); result = add_1(&e, c); if (!result) printf("Error: bad RPC call for add_1.\n"); else if (*result) printf("Error: `%s' not added, error code = %d.\n", e.n, *result); else printf("`%s' has been added.\n", e.n); }
void calcprog_1(char *host) { CLIENT *clnt; int *result_1; int add_1_arg; int *result_2; int mul_1_arg; void *result_3; int init_1_arg; #ifndef DEBUG clnt = clnt_create (host, CALCPROG, CALCVERS, "udp"); if (clnt == NULL) { clnt_pcreateerror (host); exit (1); } #endif /* DEBUG */ init_1_arg = 100; result_3 = init_1(&init_1_arg, clnt); if (result_3 == (void *) NULL) { clnt_perror (clnt, "call failed"); } printf ("init fait: \n"); add_1_arg = 12; result_1 = add_1(&add_1_arg, clnt); if (result_1 == (int *) NULL) { clnt_perror (clnt, "call failed"); } printf ("resul: %d \n", *result_1); #ifndef DEBUG clnt_destroy (clnt); #endif /* DEBUG */ }
void add_article(char *author, char *title, char *tmp_filename, char *filename) { struct add_article_in *in; article_num *num; CGI_varlist *redirect_vars; char *reason; // char *error_location; // char *success_location; // sprintf(error_location, "%s/papererror.php", WEB_BASEPHP); // sprintf(success_location, "%s/paperinfo.php", WEB_BASEPHP); FILE *fp; struct stat file_stat; fp = fopen(tmp_filename, "rb"); if (fp == NULL) { // sprintf(reason, "Error when opening file %s", strerror(errno)); redirect_vars = CGI_add_var(NULL, "reason", "Error when opening file"); printf("Status: 303\nLocation: %s%s%s\n\n", WEB_BASEPHP, "/papererror.php?", CGI_encode_varlist(redirect_vars, NULL)); CGI_free_varlist(redirect_vars); // perror("Error when opening file"); return; } stat(tmp_filename, &file_stat); in = (struct add_article_in *) malloc(sizeof(struct add_article_in)); // in->author = strdup(author); in->author = author; // in->title = strdup(title); in->title = title; in->filename = filename; in->content.content_val = malloc(sizeof(char) * file_stat.st_size); in->content.content_len = fread(in->content.content_val, 1, file_stat.st_size, fp); if (in->content.content_len == 0) { // sprintf(reason, "Error while reading file %s", strerror(errno)); redirect_vars = CGI_add_var(NULL, "reason", "Error while reading file"); printf("Status: 303\nLocation: %s%s%s\n\n", WEB_BASEPHP, "/papererror.php?", CGI_encode_varlist(redirect_vars, NULL)); CGI_free_varlist(redirect_vars); // perror("Error while reading"); fclose(fp); exit(1); } fclose(fp); num = add_1(in, cl); // char *query_string = CGI_encode_query(NULL, "id", *num, "new", "success", 0); // redirect_vars = CGI_add_var(NULL, "id", (char*)*num); // redirect_vars = CGI_add_var(redirect_vars, "new", "success"); // printf("Status: 303\nLocation: %s%s%s\n\n", WEB_BASEPHP, "/paperinfo.php?", query_string); // printf("Status: 303\nLocation: %s%s%s\n\n", WEB_BASEPHP, "/paperinfo.php?", CGI_encode_varlist(redirect_vars, NULL)); printf("Status: 303\nLocation: %s%sid=%ld&new=success\n\n", WEB_BASEPHP, "/paperinfo.php?", *num); // CGI_free_varlist(redirect_vars); // printf("%ld\n", *num); free(in->content.content_val); free(in); return; }
void main(int argc, char *argv[]) { CLIENT *cliente; int *return_value; float *f_return_value; char *servidor; if (argc < 5){ fprintf(stderr, "Usage:\n%s <server> <operation> <number 1> <number 2>\n", argv[0]); fprintf(stderr, "Example:\n%s localhost add 2 5\n", argv[0]); exit (1); } servidor = argv[1]; // Generating handle to call server. if ((cliente=clnt_create(servidor, CALCULATOR, CALCULATORVERS, "tcp")) == (CLIENT *) NULL) { clnt_pcreateerror(servidor); exit(2); } if (strcmp(argv[2], "add") == 0) { return_value = add_1(atoi(argv[3]), atoi(argv[4]), cliente); if (! *return_value) { fprintf(stderr, "error: couldn't add\n"); exit(1); } else{ printf("Return value = %d\n", *return_value); } exit(0); } else if (strcmp(argv[2], "sub") == 0) { return_value = sub_1(atoi(argv[3]), atoi(argv[4]), cliente); if (! *return_value) { fprintf(stderr, "error: couldn't sub\n"); exit(1); } else{ printf("Return value = %d\n", *return_value); } exit(0); } else if (strcmp(argv[2], "times") == 0) { return_value = times_1(atoi(argv[3]), atoi(argv[4]), cliente); if (! *return_value) { fprintf(stderr, "error: couldn't times\n"); exit(1); } else{ printf("Return value = %d\n", *return_value); } exit(0); } else if (strcmp(argv[2], "divide") == 0) { f_return_value = divide_1(atoi(argv[3]), atoi(argv[4]), cliente); if (! *f_return_value) { fprintf(stderr, "error: couldn't divide\n"); exit(1); } else{ printf("Return value = %.3f\n", *f_return_value); } exit(0); } else{ fprintf(stderr, "Avaiable operations: add, sub, times, divide\n"); } clnt_destroy(cliente); }