int main() { char a[MAXL], b[MAXL]; int len_a, start_a, numLen_a, len_b, start_b, numLen_b, i, flag; len_a = my_gets(a, MAXL); for(i = 0; i < len_a && a[i] == '0'; ++i); start_a = i; len_b = my_gets(b, MAXL); for(i = 0; i < len_b && b[i] == '0'; ++i); start_b = i; numLen_a = len_a - start_a; numLen_b = len_b - start_b; if(numLen_a < numLen_b) putchar('<'); else if(numLen_a > numLen_b) putchar('>'); else { // numLen_a == numLen_b flag = strcmp(&a[start_a], &b[start_b]); if(flag < 0) putchar('<'); else if(flag > 0) putchar('>'); else putchar('='); } putchar('\n'); return 0; }
int main() { char response[8]; puts("Continue?[y]n:"); my_gets(response); if (response[0] =='n') return 0; puts("Type something here:"); my_gets(response); printf("%s",response); return 0; }
static char * readtty(const char *pr, char *src) { char *line; line = my_gets(&elm.string, pr, src); sig_check(); if (line == NULL) (void)putc('\n', stdout); return line ? savestr(line) : __UNCONST(""); }
int main(void) { struct mg_context *ctx; struct mg_callbacks callbacks; struct WSAData wsaData; char *localIp; char passwdBuff[52]; const char *options[] = { "listening_ports", "8080", "num_threads", "1", "authentication_domain", realm, "document_root", "resources/", NULL }; memset(&callbacks, 0, sizeof(callbacks)); callbacks.begin_request = begin_request_handler; // Attempt to deduce the local IP if(WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) return -1; localIp = deduce_ip(); WSACleanup(); if(localIp != NULL) { printf("Starting remote control server on IP\n" "+------------------+\n" "| %-16s |\n" "+------------------+\n", localIp); } // Generate the htpasswd file printf("Please enter password (%i characters max., leave blank for none): ", (sizeof passwdBuff)-2); // 2 for \n\0 my_gets(passwdBuff, sizeof passwdBuff); generate_htpasswd(passwdBuff); // Start Mongoose ctx = mg_start(&callbacks, NULL, options); printf("Listening ports: \t%s\n\n", mg_get_option(ctx, "listening_ports")); printf("Press <ENTER> to terminate.\n"); getchar(); printf("Exiting...\n"); mg_stop(ctx); return EXIT_SUCCESS; }
void load_form() { char *star_const ; forever { printf("<please enter: cstar dtime temppar softpar stareff rhomin overmin>\n") ; star_const = my_gets(" ") ; if(sscanf(star_const,"%lf %lf %lf %lf %lf %lf %lf",&cstar,&dtime, &temppar,&softpar,&stareff,&rhomin,&overmin) == 7) { break ; } printf("<sorry, inconsistent input, %s>\n",title) ; } form_loaded = YES ; starform_loaded = NO ; }
int info_enter(struct student *st_inf,int num_of_students,int max_number_of_students) { int j; char input_buffer[input_buf_size]; int max_marks = 5; int name_size = SIZE (st_inf[num_of_students].name); int surname_size = SIZE(st_inf[num_of_students].surname); int facul_size = SIZE(st_inf[num_of_students].facul); int specialty_size = SIZE(st_inf[num_of_students].specialty); char group_size = SIZE(st_inf[num_of_students].group); int mark; if (num_of_students > max_number_of_students) { printf("\nMax number of students (%d) reached",max_number_of_students); return num_of_students; } printf("\nEnter the name of the student: "); my_gets(st_inf[num_of_students].name,name_size); printf("\nEnter the surname of the student: "); my_gets(st_inf[num_of_students].surname, surname_size); printf("\nEnter the name of the faculty: "); my_gets(st_inf[num_of_students].facul, facul_size); printf("\nEnter the name of the specialty student: "); my_gets(st_inf[num_of_students].specialty, specialty_size); printf("\nEnter a group of student: "); my_gets(st_inf[num_of_students].group, group_size); st_inf[num_of_students].total_marks = max_marks; for (j = 0; j < max_marks; j++) { printf("Enter mark number %d:\n", j+1); my_gets(input_buffer, input_buf_size); mark=atoi(input_buffer); if (mark<0 || mark>5) { printf("ERROR! Please enter number 1-5 !\n"); j--; } st_inf[num_of_students].marks[j] = mark; } num_of_students++; return num_of_students; }
int main() { char user_string[100]; int number; clear_screen(); printf("Please enter an int\r\n"); number = my_int_scanf(); printf("%d was the number you entered\r\n",number); printf("\r\n please enter a string \r\n"); my_gets(user_string,100); printf("the string you entered was %s\r\n",user_string); return 0; }
int my_menu(void) { char s[input_buf_size]; int N; printf("\n=> 1 <= Enter student data "); printf("\n=> 2 <= Look primed student "); printf("\n=> 3 <= Exit "); do { printf("\nEnter your choise: "); my_gets(s, input_buf_size); printf("\n"); N=atoi(s); } while(0 > N || N > 3); return N; }
void insert_data(SCHEMA *schema) { int i; void *aux; NODE *node = schema->sentry; // O arquivo .data é aberto para atualizacao char *filename = (char*)malloc(sizeof(char) * (strlen(schema->name)+6)); strcpy(filename, schema->name); strcat(filename, ".data"); FILE *fp_data = fopen(filename, "r+b"); if(fp_data == NULL) { fprintf(stderr, "could not open file\n"); exit(1); } // E o ponteiro é movido para o fim do arquivo fseek(fp_data, 0, SEEK_END); // O registro é percorrido analisando qual o tipo de dado a ser salvo na ordem desejada for(i = 0; i < schema->n_elements; i++) { node = node->next; // aux armazena os dados a serem escritos aux = malloc(node->size); // De acordo com o tipo sendo analisado, as informações são lidas da stdin e armazendas em aux if(node->id == INT_T) { scanf("%d", (int*)aux); } else if(node->id == DOUBLE_T) { scanf("%lf", (double*)aux); } else if(node->id == STRING_T) { free(aux); aux = (void*)my_gets(stdin, (node->size/sizeof(char))); } // As informacoes sao entao escritas no final do arquivo .data fwrite(aux, node->size, 1, fp_data); // A memoria alocada é liberada if(aux != NULL) free(aux); } free(filename); // E o arquivo é fechado fclose(fp_data); }
int main(int argc, char * argv[]) { if(argc != 2) { fprintf(stderr,"Error : Please enter the name of the edit file\n"); return EXIT_FAILURE; } else { FILE* edit_file = fopen(argv[1],"r"); edits_array my_edits; int i = 1; long_string current_line; char * c = current_line; fill_edits_array(my_edits,edit_file); while ( 1 ) { c = my_gets(current_line, stdin); if ( c == NULL ) break; edit_line(my_edits,current_line,i); i+=1; } free_edits_array(my_edits); free(edit_file); return EXIT_SUCCESS; } }
HRESULT __stdcall VF_ReadDataFunc_Blen( VF_FileHandle hFileHandle, DWORD dwStream,void *lpData ) { char req[256]; char buf[256]; SOCKET s_in; int width; int height; int y; int rval; unsigned char * framebuf; conndesc * c = (conndesc*) hFileHandle; LPVF_ReadData_Video v = (LPVF_ReadData_Video) lpData; if (c == 0 || dwStream != VF_STREAM_VIDEO || v == 0) { return VF_ERROR; } s_in = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (s_in < 0) { return VF_ERROR; } if (connect(s_in, (struct sockaddr*) &c->addr, sizeof(c->addr)) < 0) { goto errout; } sprintf(req, "GET /images/ppm/%d.ppm HTTP/1.0\n\n", (int) (v->dwFrameNumberL) + c->start); my_send(s_in, req); do { if (my_gets(s_in, buf, 256) <= 0) { goto errout; } } while (strcmp(buf, "P6\n") != 0); do { rval = my_gets(s_in, buf, 256); } while ( (buf[0] == '#' || buf[0] == '\n') && rval >= 0); if (sscanf(buf, "%d %d\n", &width, &height) != 2) { goto errout; } if (width != c->width || height != c->height) { goto errout; } my_gets(s_in, buf, 256); /* 255 */ framebuf = (unsigned char*) v->lpData; for (y = 0; y < height; y++) { unsigned char * p = framebuf + v->lPitch * y; unsigned char * e = p + width * 3; my_recv(s_in, (char*) p, width * 3); while (p != e) { unsigned char tmp = p[2]; p[2] = p[0]; p[0] = tmp; p += 3; } } closesocket(s_in); return VF_OK; errout: closesocket(s_in); return VF_ERROR; }
HRESULT __stdcall VF_OpenFileFunc_Blen( char *lpFileName, LPVF_FileHandle lpFileHandle ) { conndesc * rval; char * host; char * p; int port; SOCKET s_in; char buf[256]; struct sockaddr_in addr; FILE* fp; p = lpFileName; while (*p && *p != '.') p++; if (*p) p++; if (strcmp(p, "blu") != 0) { return VF_ERROR; } fp = fopen(lpFileName, "r"); if (!fp) { return VF_ERROR; } fgets(buf, 256, fp); fclose(fp); host = buf; p = host; while (*p && *p != ':') p++; if (*p) p++; p[-1] = 0; port = atoi(p); if (!port) { port = 8080; } addr.sin_family = AF_INET; addr.sin_port = htons(port); addr.sin_addr.s_addr = getipaddress(host); s_in = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (s_in < 0) { return VF_ERROR; } if (connect(s_in, (struct sockaddr*) &addr, sizeof(addr)) < 0) { closesocket(s_in); return VF_ERROR; } rval = (conndesc*) malloc(sizeof(conndesc)); rval->addr = addr; my_send(s_in, "GET /info.txt HTTP/1.0\n\n"); for (;;) { char * key; char * val; if (my_gets(s_in, buf, 250) <= 0) { break; } key = buf; val = buf; while (*val && *val != ' ') val++; if (*val) { *val = 0; val++; if (strcmp(key, "width") == 0) { rval->width = atoi(val); } else if (strcmp(key, "height") == 0) { rval->height = atoi(val); } else if (strcmp(key, "start") == 0) { rval->start = atoi(val); } else if (strcmp(key, "end") == 0) { rval->end = atoi(val); } else if (strcmp(key, "rate") == 0) { rval->rate = atoi(val); } else if (strcmp(key, "ratescale") == 0) { rval->ratescale = atoi(val); } } } closesocket(s_in); *lpFileHandle = (VF_FileHandle) rval; return VF_OK; }