int wmain() { WCHAR desc[255]; int (FAR STDAPICALLTYPE * GetUName)(WORD wCharCode, LPWSTR lpbuf); HINSTANCE hGetUName = LoadLibraryW(L"getuname.dll"); //getUName GetUName; if (hGetUName != NULL) { (FARPROC&)GetUName = /*(getUName)*/GetProcAddress(hGetUName,"GetUName"); if (GetUName == NULL) { FreeLibrary(hGetUName); return 1; } } wprintf(L"Please type a character:"); WCHAR ch = getwchar(); int res = GetUName(ch,desc); if (desc == NULL) { wprintf(L"Error %d",res); return 1; } wprintf(L"U+%04X: %s",ch,desc); wprintf(L"Press return to exit."); getwchar(); return 0; }
JNIEXPORT jboolean JNICALL Java_mjava_io_SimpleInputStream_hasnextLine (JNIEnv * env, jobject obj) { setlocale(LC_ALL, "Chinese-simplified"); // <clocale> wchar_t ch = getwchar(); if(ch == WEOF) return 0; // 不要用EOF //if(ch == L'E') return 0; // 测试:读到E开头的字符串就退出 ungetwc(ch, stdin); return 1; }
int ReadCmdFromCin(wchar_t* cmd, size_t size) { wchar_t c; uint32 index = 0; while (index < size - 1) { c = getwchar(); if (c == '\r' || c == '\n') break; cmd[index++] = c; } while (index < size && c != '\n'); cmd[index] = 0; return index; }
/* * Fold the contents of standard input to fit within WIDTH columns (or bytes) * and write to standard output. * * If sflag is set, split the line at the last space character on the line. * This flag necessitates storing the line in a buffer until the current * column > width, or a newline or EOF is read. * * The buffer can grow larger than WIDTH due to backspaces and carriage * returns embedded in the input stream. */ void fold(int width) { static wchar_t *buf; static int buf_max; int col, i, indx, space; wint_t ch; col = indx = 0; while ((ch = getwchar()) != WEOF) { if (ch == '\n') { wprintf(L"%.*ls\n", indx, buf); col = indx = 0; continue; } if ((col = newpos(col, ch)) > width) { if (sflag) { i = indx; while (--i >= 0 && !iswblank(buf[i])) ; space = i; } if (sflag && space != -1) { space++; wprintf(L"%.*ls\n", space, buf); wmemmove(buf, buf + space, indx - space); indx -= space; col = 0; for (i = 0; i < indx; i++) col = newpos(col, buf[i]); } else { wprintf(L"%.*ls\n", indx, buf); col = indx = 0; } col = newpos(col, ch); } if (indx + 1 > buf_max) { buf_max += LINE_MAX; buf = realloc(buf, sizeof(*buf) * buf_max); if (buf == NULL) err(1, "realloc()"); } buf[indx++] = ch; } if (indx != 0) wprintf(L"%.*ls", indx, buf); }
static void wide (const char *path) { FILE *old_stdin = stdin; stdin = xfopen (path, "r"); TEST_COMPARE (getwchar (), L'a'); TEST_COMPARE (getwchar_unlocked (), L'b'); wchar_t ch = 1; TEST_COMPARE (wscanf (L"%lc", &ch), 1); TEST_COMPARE (ch, L'c'); TEST_COMPARE (call_vwscanf (L"%lc", &ch), 1); TEST_COMPARE (ch, L'd'); fclose (stdin); stdin = old_stdin; }
char* getstr () { wchar_t *str; char *ret; wint_t i = 1; size_t j; /* assuming a sentence contains at most 200 wide characters */ size_t WCHAR_MAX_SIZE = sizeof (wchar_t) * 200; str = (wchar_t *) malloc (WCHAR_MAX_SIZE); while ('\n' != (str[i - 1] = getwchar ())) { if (str[i - 1] == WEOF) break; i ++; } str[i - 1] = L'\0'; j = MB_CUR_MAX * (wcslen (str) + 1); ret = (char *) malloc (j); wcstombs (ret, str, j); ret[j - 1] = '\0'; free (str); return ret; }
int main() { //inicializacion de semilla srand( (unsigned) std::time(NULL)); //Leemos los valores de configuracion float probabilidad_cruza = utils::strToFloat(config.getValue("cruza")); float probabilidad_mutacion = utils::strToFloat(config.getValue("mutacion")); unsigned int tamanio_poblacion = utils::strToInt(config.getValue("tamanio_poblacion")); unsigned int variables_fenotipo = utils::strToInt(config.getValue("variables_fenotipo")); unsigned int cantidad_generaciones = utils::strToInt(config.getValue("cantidad_generaciones")); unsigned int cantidad_genes = utils::strToInt(config.getValue("cantidad_genes")); float escala = utils::strToFloat(config.getValue("escala")); unsigned int elitismo = utils::strToInt(config.getValue("elitismo")); unsigned int id_funcion_fitness = utils::strToInt(config.getValue("id_funcion_fitness")); std::string forma_seleccion = config.getValue("forma_seleccion"); float error = utils::strToFloat(config.getValue("error")); unsigned int brecha_generacional = utils::strToInt(config.getValue("brecha_generacional")); unsigned int k_competencia = utils::strToInt(config.getValue("k_competencia")); float fitness_deseado = utils::strToFloat(config.getValue("fitness_deseado")); std::cout<<"Bienvenidos al Ejercicio 1\n"; std::cout<<"Tamanio de poblacion = "<<tamanio_poblacion<<'\n'; std::cout<<"Metodo de seleccion = "<<forma_seleccion<<'\n'; std::cout<<"Probabilidad Cruza = "<<probabilidad_cruza<<'\n'; std::cout<<"Probabilidad Mutacion = "<<probabilidad_mutacion<<'\n'; std::cout<<"Elitismo = "<<elitismo<<'\n'; unsigned int metodo_seleccion; if(forma_seleccion.compare("ruleta") == 0) metodo_seleccion = AlgoritmoGenetico::SELECCION_RULETA; else if(forma_seleccion.compare("ventanas") == 0) metodo_seleccion = AlgoritmoGenetico::SELECCION_VENTANAS; else if(forma_seleccion.compare("competencia") == 0) metodo_seleccion = AlgoritmoGenetico::SELECCION_COMPETENCIA; else std::cout<<"Metodo de seleccion no definido\n"; //Instanciamos el algoritmo genetico AlgoritmoGenetico AG (tamanio_poblacion, cantidad_genes, escala, variables_fenotipo, cantidad_generaciones, probabilidad_cruza, probabilidad_mutacion, elitismo, brecha_generacional, id_funcion_fitness, metodo_seleccion, k_competencia); //Definimos vectores para graficación std::vector<float> mejor_fitness, prom_fitness, peor_fitness; //Guardo el mejor fitness de la poblacion mejor_fitness.push_back(AG.getMejorFitness()); //Calculo y guardo el fitness promedio de la poblacion std::vector<float> vector_tmp_fitness; AG.getFitness(vector_tmp_fitness); prom_fitness.push_back(utils::promedio(vector_tmp_fitness)); //Guardo el Peor fitness de la poblacion peor_fitness.push_back(AG.getPeorFitness()); float mejor_fitness_actual = 10.0; unsigned int w; for (w = 0; w < cantidad_generaciones; w++) { AG.reproduccion(); mejor_fitness_actual = AG.evaluar(); std::cout<<"Mejor fitness a iteracion "<<w<<" = "<<mejor_fitness_actual<<'\n'; //Guardo el mejor fitness de la poblacion mejor_fitness.push_back(AG.getMejorFitness()); //Calculo y guardo el fitness promedio de la poblacion std::vector<float> vector_tmp_fitness; AG.getFitness(vector_tmp_fitness); prom_fitness.push_back(utils::promedio(vector_tmp_fitness)); //Guardo el Peor fitness de la poblacion peor_fitness.push_back(AG.getPeorFitness()); //Criterio de finalización if (mejor_fitness_actual > fitness_deseado) { break; } } std::cout<<"Se termino luego de "<<w<<" generaciones.\nEl fitness logrado es de "<<mejor_fitness.back()<<'\n'; AG.imprimirResumen(); std::vector<bool> respuesta; AG.getMejorGenotipo(respuesta); if(id_funcion_fitness == 1 or id_funcion_fitness == 2) std::cout<<"\nSolucion = "<<utils::binary2int(respuesta)/escala; if(id_funcion_fitness == 3) { std::vector<int> soluciones; utils::vectorBinary2Int(respuesta,soluciones, 18); std::cout<<"\nSoluciones = "; for (unsigned int i = 0; i < soluciones.size(); i++) std::cout<<soluciones[i]/escala<<' '; } std::cout<<" con fitness = "<<mejor_fitness_actual<<'\n'; //Vector de vector para graficacion std::vector<std::vector<float> > grafica; grafica.push_back(mejor_fitness); grafica.push_back(prom_fitness); grafica.push_back(peor_fitness); GNUPlot plotter; utils::drawHistory(grafica, plotter, id_funcion_fitness); std::cout<<"\nFin del Algoritmo Genetico. Ahora se realizara el metodo de gradiente desciendiente\n"; getwchar(); //Gradiente std::vector<float> x_ini; switch(id_funcion_fitness){ case 1: { //ejercicio 1a x_ini.push_back(359.0); break; } case 2: { //ejercicio 1b x_ini.push_back(2.0); break; } case 3: { //ejercicio 1c x_ini.push_back(0.1); x_ini.push_back(0.1); break; } } std::cout<<"Gradiente inicializado en "; utils::printVector((x_ini)); //float tasa_inicial = 0.1; //tasa para 1a //float tasa_inicial = 0.01; //tasa para 1b float tasa_inicial = 0.01; //tasa para 1c float criterio_error = 0.0001; unsigned int maxit = 300; Gradiente gradiente(tasa_inicial, x_ini, id_funcion_fitness, criterio_error, maxit); unsigned int iteraciones; iteraciones = gradiente.descender(); std::vector<float> solucion_segun_gradiente = gradiente.getSolucion(); std::cout<<"\nGradiente descendiente:\nIteraciones = "<<iteraciones; std::cout<<"\nSolucion del gradiente = "; utils::printVector(solucion_segun_gradiente); getwchar(); return 0; }
int main(int argc, char **argv) { wint_t ch; CHAR *c; CSET cur_set; /* current character set */ LINE *l; /* current line */ int extra_lines; /* # of lines above first line */ int cur_col; /* current column */ int cur_line; /* line number of current position */ int max_line; /* max value of cur_line */ int this_line; /* line l points to */ int nflushd_lines; /* number of lines that were flushed */ int adjust, opt, warned, width; (void)setlocale(LC_CTYPE, ""); max_bufd_lines = 128; compress_spaces = 1; /* compress spaces into tabs */ while ((opt = getopt(argc, argv, "bfhl:px")) != -1) switch (opt) { case 'b': /* do not output backspaces */ no_backspaces = 1; break; case 'f': /* allow half forward line feeds */ fine = 1; break; case 'h': /* compress spaces into tabs */ compress_spaces = 1; break; case 'l': /* buffered line count */ if ((max_bufd_lines = atoi(optarg)) <= 0) errx(1, "bad -l argument %s", optarg); break; case 'p': /* pass unknown control sequences */ pass_unknown_seqs = 1; break; case 'x': /* do not compress spaces into tabs */ compress_spaces = 0; break; case '?': default: usage(); } if (optind != argc) usage(); /* this value is in half lines */ max_bufd_lines *= 2; adjust = cur_col = extra_lines = warned = 0; cur_line = max_line = nflushd_lines = this_line = 0; cur_set = last_set = CS_NORMAL; lines = l = alloc_line(); while ((ch = getwchar()) != WEOF) { if (!iswgraph(ch)) { switch (ch) { case BS: /* can't go back further */ if (cur_col == 0) continue; --cur_col; continue; case CR: cur_col = 0; continue; case ESC: /* just ignore EOF */ switch(getwchar()) { case RLF: cur_line -= 2; break; case RHLF: cur_line--; break; case FHLF: cur_line++; if (cur_line > max_line) max_line = cur_line; } continue; case NL: cur_line += 2; if (cur_line > max_line) max_line = cur_line; cur_col = 0; continue; case SPACE: ++cur_col; continue; case SI: cur_set = CS_NORMAL; continue; case SO: cur_set = CS_ALTERNATE; continue; case TAB: /* adjust column */ cur_col |= 7; ++cur_col; continue; case VT: cur_line -= 2; continue; } if (iswspace(ch)) { if ((width = wcwidth(ch)) > 0) cur_col += width; continue; } if (!pass_unknown_seqs) continue; } /* Must stuff ch in a line - are we at the right one? */ if (cur_line != this_line - adjust) { LINE *lnew; int nmove; adjust = 0; nmove = cur_line - this_line; if (!fine) { /* round up to next line */ if (cur_line & 1) { adjust = 1; nmove++; } } if (nmove < 0) { for (; nmove < 0 && l->l_prev; nmove++) l = l->l_prev; if (nmove) { if (nflushd_lines == 0) { /* * Allow backup past first * line if nothing has been * flushed yet. */ for (; nmove < 0; nmove++) { lnew = alloc_line(); l->l_prev = lnew; lnew->l_next = l; l = lines = lnew; extra_lines++; } } else { if (!warned++) dowarn(cur_line); cur_line -= nmove; } } } else { /* may need to allocate here */ for (; nmove > 0 && l->l_next; nmove--) l = l->l_next; for (; nmove > 0; nmove--) { lnew = alloc_line(); lnew->l_prev = l; l->l_next = lnew; l = lnew; } } this_line = cur_line + adjust; nmove = this_line - nflushd_lines; if (nmove >= max_bufd_lines + BUFFER_MARGIN) { nflushd_lines += nmove - max_bufd_lines; flush_lines(nmove - max_bufd_lines); } } /* grow line's buffer? */ if (l->l_line_len + 1 >= l->l_lsize) { int need; need = l->l_lsize ? l->l_lsize * 2 : 90; if ((l->l_line = realloc(l->l_line, (unsigned)need * sizeof(CHAR))) == NULL) err(1, (char *)NULL); l->l_lsize = need; } c = &l->l_line[l->l_line_len++]; c->c_char = ch; c->c_set = cur_set; c->c_column = cur_col; c->c_width = wcwidth(ch); /* * If things are put in out of order, they will need sorting * when it is flushed. */ if (cur_col < l->l_max_col) l->l_needs_sort = 1; else l->l_max_col = cur_col; if (c->c_width > 0) cur_col += c->c_width; } if (ferror(stdin)) err(1, NULL); if (max_line == 0) exit(0); /* no lines, so just exit */ /* goto the last line that had a character on it */ for (; l->l_next; l = l->l_next) this_line++; flush_lines(this_line - nflushd_lines + extra_lines + 1); /* make sure we leave things in a sane state */ if (last_set != CS_NORMAL) PUTC('\017'); /* flush out the last few blank lines */ nblank_lines = max_line - this_line; if (max_line & 1) nblank_lines++; else if (!nblank_lines) /* missing a \n on the last line? */ nblank_lines = 2; flush_blanks(); exit(0); }
int main(int argc, char *argv[]) { const char *curfile; wint_t wc; int c, column; int n; int rval; int width; setlocale(LC_CTYPE, ""); /* handle obsolete syntax */ while (argc > 1 && argv[1][0] == '-' && isdigit((unsigned char)argv[1][1])) { getstops(&argv[1][1]); argc--; argv++; } while ((c = getopt (argc, argv, "t:")) != -1) { switch (c) { case 't': getstops(optarg); break; case '?': default: usage(); /* NOTREACHED */ } } argc -= optind; argv += optind; rval = 0; do { if (argc > 0) { if (freopen(argv[0], "r", stdin) == NULL) { warn("%s", argv[0]); rval = 1; argc--, argv++; continue; } curfile = argv[0]; argc--, argv++; } else curfile = "stdin"; column = 0; while ((wc = getwchar()) != WEOF) { switch (wc) { case '\t': if (nstops == 0) { do { putwchar(' '); column++; } while (column & 07); continue; } if (nstops == 1) { do { putwchar(' '); column++; } while (((column - 1) % tabstops[0]) != (tabstops[0] - 1)); continue; } for (n = 0; n < nstops; n++) if (tabstops[n] > column) break; if (n == nstops) { putwchar(' '); column++; continue; } while (column < tabstops[n]) { putwchar(' '); column++; } continue; case '\b': if (column) column--; putwchar('\b'); continue; default: putwchar(wc); if ((width = wcwidth(wc)) > 0) column += width; continue; case '\n': putwchar(wc); column = 0; continue; } } if (ferror(stdin)) { warn("%s", curfile); rval = 1; } } while (argc > 0); exit(rval); }
int main() { mbstate_t mb = {0}; size_t s = 0; tm tm = {0}; wint_t w = 0; ::FILE* fp = 0; __darwin_va_list va; char* ns = 0; wchar_t* ws = 0; static_assert((std::is_same<decltype(fwprintf(fp, L"")), int>::value), ""); static_assert((std::is_same<decltype(fwscanf(fp, L"")), int>::value), ""); static_assert((std::is_same<decltype(swprintf(ws, s, L"")), int>::value), ""); static_assert((std::is_same<decltype(swscanf(L"", L"")), int>::value), ""); static_assert((std::is_same<decltype(vfwprintf(fp, L"", va)), int>::value), ""); static_assert((std::is_same<decltype(vfwscanf(fp, L"", va)), int>::value), ""); static_assert((std::is_same<decltype(vswprintf(ws, s, L"", va)), int>::value), ""); static_assert((std::is_same<decltype(vswscanf(L"", L"", va)), int>::value), ""); static_assert((std::is_same<decltype(vwprintf(L"", va)), int>::value), ""); static_assert((std::is_same<decltype(vwscanf(L"", va)), int>::value), ""); static_assert((std::is_same<decltype(wprintf(L"")), int>::value), ""); static_assert((std::is_same<decltype(wscanf(L"")), int>::value), ""); static_assert((std::is_same<decltype(fgetwc(fp)), wint_t>::value), ""); static_assert((std::is_same<decltype(fgetws(ws, 0, fp)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(fputwc(L' ', fp)), wint_t>::value), ""); static_assert((std::is_same<decltype(fputws(L"", fp)), int>::value), ""); static_assert((std::is_same<decltype(fwide(fp, 0)), int>::value), ""); static_assert((std::is_same<decltype(getwc(fp)), wint_t>::value), ""); static_assert((std::is_same<decltype(getwchar()), wint_t>::value), ""); static_assert((std::is_same<decltype(putwc(L' ', fp)), wint_t>::value), ""); static_assert((std::is_same<decltype(putwchar(L' ')), wint_t>::value), ""); static_assert((std::is_same<decltype(ungetwc(L' ', fp)), wint_t>::value), ""); static_assert((std::is_same<decltype(wcstod(L"", (wchar_t**)0)), double>::value), ""); static_assert((std::is_same<decltype(wcstof(L"", (wchar_t**)0)), float>::value), ""); static_assert((std::is_same<decltype(wcstold(L"", (wchar_t**)0)), long double>::value), ""); static_assert((std::is_same<decltype(wcstol(L"", (wchar_t**)0, 0)), long>::value), ""); static_assert((std::is_same<decltype(wcstoll(L"", (wchar_t**)0, 0)), long long>::value), ""); static_assert((std::is_same<decltype(wcstoul(L"", (wchar_t**)0, 0)), unsigned long>::value), ""); static_assert((std::is_same<decltype(wcstoull(L"", (wchar_t**)0, 0)), unsigned long long>::value), ""); static_assert((std::is_same<decltype(wcscpy(ws, L"")), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcsncpy(ws, L"", s)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcscat(ws, L"")), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcsncat(ws, L"", s)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcscmp(L"", L"")), int>::value), ""); static_assert((std::is_same<decltype(wcscoll(L"", L"")), int>::value), ""); static_assert((std::is_same<decltype(wcsncmp(L"", L"", s)), int>::value), ""); static_assert((std::is_same<decltype(wcsxfrm(ws, L"", s)), size_t>::value), ""); static_assert((std::is_same<decltype(wcschr((wchar_t*)0, L' ')), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcscspn(L"", L"")), size_t>::value), ""); static_assert((std::is_same<decltype(wcslen(L"")), size_t>::value), ""); static_assert((std::is_same<decltype(wcspbrk((wchar_t*)0, L"")), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcsrchr((wchar_t*)0, L' ')), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcsspn(L"", L"")), size_t>::value), ""); static_assert((std::is_same<decltype(wcsstr((wchar_t*)0, L"")), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcstok(ws, L"", (wchar_t**)0)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wmemchr((wchar_t*)0, L' ', s)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wmemcmp(L"", L"", s)), int>::value), ""); static_assert((std::is_same<decltype(wmemcpy(ws, L"", s)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wmemmove(ws, L"", s)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wmemset(ws, L' ', s)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcsftime(ws, s, L"", &tm)), size_t>::value), ""); static_assert((std::is_same<decltype(btowc(0)), wint_t>::value), ""); static_assert((std::is_same<decltype(wctob(w)), int>::value), ""); static_assert((std::is_same<decltype(mbsinit(&mb)), int>::value), ""); static_assert((std::is_same<decltype(mbrlen("", s, &mb)), size_t>::value), ""); static_assert((std::is_same<decltype(mbrtowc(ws, "", s, &mb)), size_t>::value), ""); static_assert((std::is_same<decltype(wcrtomb(ns, L' ', &mb)), size_t>::value), ""); static_assert((std::is_same<decltype(mbsrtowcs(ws, (const char**)0, s, &mb)), size_t>::value), ""); static_assert((std::is_same<decltype(wcsrtombs(ns, (const wchar_t**)0, s, &mb)), size_t>::value), ""); }
int main(int argc, char *argv[]) { u_long column, start, stop; int ch, width; char *p; setlocale(LC_ALL, ""); while ((ch = getopt(argc, argv, "")) != -1) switch(ch) { case '?': default: usage(); } argc -= optind; argv += optind; start = stop = 0; switch(argc) { case 2: stop = strtol(argv[1], &p, 10); if (stop <= 0 || *p) errx(1, "illegal column -- %s", argv[1]); /* FALLTHROUGH */ case 1: start = strtol(argv[0], &p, 10); if (start <= 0 || *p) errx(1, "illegal column -- %s", argv[0]); break; case 0: break; default: usage(); } if (stop && start > stop) errx(1, "illegal start and stop columns"); for (column = 0;;) { switch (ch = getwchar()) { case WEOF: check(stdin); break; case '\b': if (column) --column; break; case '\n': column = 0; break; case '\t': column = (column + TAB) & ~(TAB - 1); break; default: if ((width = wcwidth(ch)) > 0) column += width; break; } if ((!start || column < start || (stop && column > stop)) && putwchar(ch) == WEOF) check(stdout); } }
int main(int argc, char **argv) { ISpVoice *pVoice = NULL; WCHAR line_buffer[LINE_LENGTH]; bool exitflag = FALSE; int counter = 0; if (FAILED(::CoInitialize(NULL))) { printf("ERROR: Couldn't initialise COM.\n"); return FALSE; } HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice); if( SUCCEEDED( hr ) ) { // For some reason, if you don't do this, speech cuts out // (only on first announcement)... pVoice->Speak(L" ", SPF_IS_NOT_XML, NULL); // Main loop... while( ! exitflag ) { for(counter = 0; counter < LINE_LENGTH; counter++ ) { // Fill up the buffer... line_buffer[counter] = getwchar(); // Check for exit condition... if( line_buffer[counter] == WEOF ) { line_buffer[counter] = 0; exitflag = TRUE; break; } // Break at end of line... if( line_buffer[counter] == L'\n' ) { line_buffer[counter] = 0; break; } } counter = 0; // Should the synth's UI be displayed? if ( line_buffer == L"DisplayUI" ) { int supported = 0; hr = pVoice->IsUISupported(SPDUI_EngineProperties, NULL, NULL, &supported); if( SUCCEEDED( hr ) && supported ) { hr = pVoice->DisplayUI(NULL, NULL, SPDUI_EngineProperties, NULL, NULL); if( ! SUCCEEDED( hr ) ) { pVoice->Speak(L"There was an error displaying the properties window.\n", SPF_IS_NOT_XML|SPF_ASYNC|SPF_PURGEBEFORESPEAK, NULL); } } else { pVoice->Speak(L"Your current voice doesn't support a properties window.\n", SPF_IS_NOT_XML|SPF_ASYNC|SPF_PURGEBEFORESPEAK, NULL); } } // Was the message high-priority? if( line_buffer[0] == L'!' ) { line_buffer[0] = L' '; pVoice->Speak(line_buffer, SPF_IS_NOT_XML|SPF_ASYNC|SPF_PURGEBEFORESPEAK, NULL); } else { pVoice->Speak(line_buffer, SPF_IS_NOT_XML|SPF_ASYNC, NULL); } } // Allow the user to hear the rest of the speech buffer... pVoice->Speak(L" ", SPF_IS_NOT_XML, NULL); pVoice->Release(); pVoice = NULL; } else { printf("ERROR: Couldn't initialise SAPI 5.1.\n"); } ::CoUninitialize(); return TRUE; }
int getchar_(){ if( _bbusew ) return getwchar(); return getchar(); }
int main() { //inicializacion de semilla srand( (unsigned) std::time(NULL)); //Leemos los valores de configuracion unsigned int cantidad_de_particulas = utils::strToInt(config.getValue("cantidad_de_particulas")); float c1 = utils::strToFloat(config.getValue("c1")); float c2 = utils::strToFloat(config.getValue("c2")); float error = utils::strToFloat(config.getValue("error")); unsigned int maxit = utils::strToInt(config.getValue("maxit")); unsigned int id_funcion_fitness = utils::strToInt(config.getValue("id_funcion_fitness")); unsigned int entorno_size = utils::strToInt(config.getValue("entorno_size")); std::cout<<"Bienvenidos al Ejercicio 3\n"; std::cout<<"Cantidad de Partículas = "<<cantidad_de_particulas<<'\n'; std::cout<<"C1 = "<<c1<<'\n'; std::cout<<"C2 = "<<c2<<'\n'; std::cout<<"Iteraciones Máximas = "<<maxit<<'\n'; std::cout<<"ID funcion fitness = "<<id_funcion_fitness<<'\n'; std::cout<<"Tamaño del Entorno Anillo = "<<entorno_size<<'\n'; std::vector<std::vector<float> > limites; if (id_funcion_fitness == 1) utils::parseCSV("limites3a.csv", limites); else if (id_funcion_fitness == 2) utils::parseCSV("limites3b.csv", limites); else if (id_funcion_fitness == 3) utils::parseCSV("limites3c.csv", limites); std::vector<float> limites_inf = limites[0]; std::vector<float> limites_sup = limites[1]; std::cout<<"Limites Inferiores = "; utils::printVector(limites_inf); std::cout<<"Limites Superiores = "; utils::printVector(limites_sup); float mejor_f_n_1 = 10; Enjambre enjambre (limites_inf, limites_sup, maxit, cantidad_de_particulas, id_funcion_fitness, c1, c2, entorno_size); unsigned int i = 0; for (; i < maxit; i++) { if(!enjambre.iterar()) break; std::vector<float> solucion = enjambre.getSolucion(); float mejor_f = enjambre.getMejorFitness(); /* std::cout<<mejor_f<<" "<<mejor_f_n_1<<'\n'; if (fabs(mejor_f - mejor_f_n_1) < error) { std::cout<<"Se terminaro a iteracion "<<i<<" porque el cambio en el fitness es menor a "<<error<<'\n'; break; } mejor_f_n_1 = mejor_f; */ if(i % 10 == 0) { std::cout<<"Fitness = "<<mejor_f<<". Solucion a iteracion "<<i<<" = "; utils::printVector(solucion); } } std::vector<float> solucion = enjambre.getSolucion(); std::cout<<"Solucion a iteracion "<<i<<" = "; utils::printVector(solucion); getwchar(); return 0; }
void pausa(){ cout << "\n\nPresione enter para volver al menu."; getwchar(); getwchar(); }
static int tabify(const char *curfile) { int dcol, doneline, limit, n, ocol, width; wint_t ch; limit = nstops == 1 ? INT_MAX : tabstops[nstops - 1] - 1; doneline = ocol = dcol = 0; while ((ch = getwchar()) != WEOF) { if (ch == ' ' && !doneline) { if (++dcol >= limit) doneline = 1; continue; } else if (ch == '\t') { if (nstops == 1) { dcol = (1 + dcol / tabstops[0]) * tabstops[0]; continue; } else { for (n = 0; tabstops[n] - 1 < dcol && n < nstops; n++) ; if (n < nstops - 1 && tabstops[n] - 1 < limit) { dcol = tabstops[n]; continue; } doneline = 1; } } /* Output maximal number of tabs. */ if (nstops == 1) { while (((ocol + tabstops[0]) / tabstops[0]) <= (dcol / tabstops[0])) { if (dcol - ocol < 2) break; putwchar('\t'); ocol = (1 + ocol / tabstops[0]) * tabstops[0]; } } else { for (n = 0; tabstops[n] - 1 < ocol && n < nstops; n++) ; while (ocol < dcol && n < nstops && ocol < limit) { putwchar('\t'); ocol = tabstops[n++]; } } /* Then spaces. */ while (ocol < dcol && ocol < limit) { putwchar(' '); ocol++; } if (ch == '\b') { putwchar('\b'); if (ocol > 0) ocol--, dcol--; } else if (ch == '\n') { putwchar('\n'); doneline = ocol = dcol = 0; continue; } else if (ch != ' ' || dcol > limit) { putwchar(ch); if ((width = wcwidth(ch)) > 0) ocol += width, dcol += width; } /* * Only processing leading blanks or we've gone past the * last tab stop. Emit remainder of this line unchanged. */ if (!all || dcol >= limit) { while ((ch = getwchar()) != '\n' && ch != WEOF) putwchar(ch); if (ch == '\n') putwchar('\n'); doneline = ocol = dcol = 0; } } if (ferror(stdin)) { warn("%s", curfile); return (1); } return (0); }
int main(int argc, char *argv[]) { char buffer[BUFSIZ]; wchar_t wbuffer[BUFSIZ]; char *buf; wchar_t *wbuf; FILE *f; off_t off; fpos_t pos; size_t size; int fd, r; char c; wchar_t wc; if ((fd = dup(1)) == -1) err(2, "dup"); if ((dup_stdout = fdopen(fd, "w")) == NULL) err(2, "fdopen"); if ((fd = mkstemp(filename)) == -1) err(2, "mkstemp"); if (write(fd, "0123456789\n\n", 12) != 12 || close(fd)) err(2, "write + close"); /* status */ TEST_UNCHANGED(fwide(f, 0)); TEST_NARROW(fwide(f, -1)); TEST_WIDE(fwide(f, 1)); TEST_UNCHANGED(feof(f)); TEST_UNCHANGED(ferror(f)); TEST_UNCHANGED(fileno(f)); TEST_UNCHANGED(clearerr(f)); /* flush and purge */ TEST_UNCHANGED(fflush(f)); TEST_UNCHANGED(fpurge(f)); /* positioning */ TEST_UNCHANGED(fgetpos(f, &pos)); TEST_UNCHANGED(fgetpos(f, &pos); fsetpos(f, &pos)); TEST_UNCHANGED(ftell(f)); TEST_UNCHANGED(ftello(f)); TEST_UNCHANGED(fseek(f, 1, SEEK_CUR)); TEST_UNCHANGED(fseek(f, 1, SEEK_SET)); TEST_UNCHANGED(fseek(f, 1, SEEK_END)); TEST_UNCHANGED(fseeko(f, 1, SEEK_CUR)); TEST_UNCHANGED(fseeko(f, 1, SEEK_SET)); TEST_UNCHANGED(fseeko(f, 1, SEEK_END)); TEST_UNCHANGED(rewind(f)); /* buffering */ TEST_UNCHANGED(setbuf(f, NULL)); TEST_UNCHANGED(setbuf(f, buffer)); TEST_UNCHANGED(setvbuf(f, buffer, _IONBF, BUFSIZ)); TEST_UNCHANGED(setvbuf(f, buffer, _IOLBF, BUFSIZ)); TEST_UNCHANGED(setvbuf(f, buffer, _IOFBF, BUFSIZ)); TEST_UNCHANGED(setvbuf(f, NULL, _IONBF, 0)); TEST_UNCHANGED(setvbuf(f, NULL, _IOLBF, 0)); TEST_UNCHANGED(setvbuf(f, NULL, _IOFBF, 0)); TEST_UNCHANGED(setbuffer(f, NULL, 0)); TEST_UNCHANGED(setbuffer(f, buffer, BUFSIZ)); TEST_UNCHANGED(setlinebuf(f)); /* locking */ TEST_UNCHANGED(flockfile(f);funlockfile(f)); TEST_UNCHANGED(ftrylockfile(f);funlockfile(f)); /* input */ TEST_NARROW(getc(f)); TEST_NARROW(getc_unlocked(f)); TEST_NARROW(fgetc(f)); TEST_NARROW(c = fgetc(f); ungetc(c, f)); TEST_NARROW(fgets(buffer, BUFSIZ, f)); TEST_NARROW(fscanf(f, "%s\n", buffer)); TEST_NARROW(fgetln(f, &size)); /* output */ TEST_NARROW(putc('c', f)); TEST_NARROW(putc_unlocked('c', f)); TEST_NARROW(fputc('c', f)); TEST_NARROW(fputs("foo", f)); TEST_NARROW(fprintf(f, "%s\n", "foo")); /* input from stdin */ TEST_NARROW_STD(stdin, getchar()); TEST_NARROW_STD(stdin, getchar_unlocked()); TEST_NARROW_STD(stdin, fgets(buffer, BUFSIZ, stdin)); TEST_NARROW_STD(stdin, scanf("%s\n", buffer)); /* output to stdout */ TEST_NARROW_STD(stdout, putchar('c')); TEST_NARROW_STD(stdout, putchar_unlocked('c')); TEST_NARROW_STD(stdout, puts("foo")); TEST_NARROW_STD(stdout, printf("foo")); /* word-size ops */ /* * fread and fwrite are specified as being implemented in * terms of fgetc() and fputc() and therefore must set the * stream orientation to narrow. */ TEST_NARROW(fread(buffer, 4, BUFSIZ / 4, f)); TEST_NARROW(fwrite(buffer, 4, BUFSIZ / 4, f)); /* * getw() and putw() aren't specified anywhere but logically * should behave the same as fread/fwrite. Not all OSes agree: * Solaris 10 has them not changing the orientation. */ TEST_NARROW(getw(f)); TEST_NARROW(putw(1234, f)); /* WIDE CHAR TIME! */ /* input */ TEST_WIDE(getwc(f)); TEST_WIDE(fgetwc(f)); TEST_WIDE(wc = fgetwc(f); ungetwc(wc, f)); TEST_WIDE(fgetws(wbuffer, BUFSIZ, f)); TEST_WIDE(fwscanf(f, L"%s\n", wbuffer)); /* output */ TEST_WIDE(putwc(L'c', f)); TEST_WIDE(fputwc(L'c', f)); TEST_WIDE(fputws(L"foo", f)); TEST_WIDE(fwprintf(f, L"%s\n", L"foo")); /* input from stdin */ TEST_WIDE_STD(stdin, getwchar()); TEST_WIDE_STD(stdin, wscanf(L"%s\n", wbuffer)); /* output to stdout */ TEST_WIDE_STD(stdout, putwchar(L'c')); TEST_WIDE_STD(stdout, wprintf(L"foo")); /* memory streams */ f = open_memstream(&buf, &size); if (!((r = fwide(f, 0)) < 0)) fail(__LINE__, r, "<", "open_memstream()"); fclose(f); f = open_wmemstream(&wbuf, &size); if (!((r = fwide(f, 0)) > 0)) fail(__LINE__, r, ">", "open_wmemstream()"); fclose(f); /* random stuff? */ TEST_UNCHANGED_STD(stderr, perror("foo")); remove(filename); if (failures) exit(1); exit(0); }
int main() { // mbstate_t comes from the underlying C library; it is defined (in C99) as: // a complete object type other than an array type that can hold the conversion // state information necessary to convert between sequences of multibyte // characters and wide characters #if defined(__clang__) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wmissing-braces" #endif mbstate_t mb = {0}; #if defined(__clang__) #pragma clang diagnostic pop #endif size_t s = 0; tm *tm = 0; wint_t w = 0; ::FILE* fp = 0; #ifdef __APPLE__ __darwin_va_list va; #else __builtin_va_list va; #endif char* ns = 0; wchar_t* ws = 0; static_assert((std::is_same<decltype(fwprintf(fp, L"")), int>::value), ""); static_assert((std::is_same<decltype(fwscanf(fp, L"")), int>::value), ""); static_assert((std::is_same<decltype(swprintf(ws, s, L"")), int>::value), ""); static_assert((std::is_same<decltype(swscanf(L"", L"")), int>::value), ""); static_assert((std::is_same<decltype(vfwprintf(fp, L"", va)), int>::value), ""); static_assert((std::is_same<decltype(vfwscanf(fp, L"", va)), int>::value), ""); static_assert((std::is_same<decltype(vswprintf(ws, s, L"", va)), int>::value), ""); static_assert((std::is_same<decltype(vswscanf(L"", L"", va)), int>::value), ""); static_assert((std::is_same<decltype(fgetwc(fp)), wint_t>::value), ""); static_assert((std::is_same<decltype(fgetws(ws, 0, fp)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(fputwc(L' ', fp)), wint_t>::value), ""); static_assert((std::is_same<decltype(fputws(L"", fp)), int>::value), ""); static_assert((std::is_same<decltype(fwide(fp, 0)), int>::value), ""); static_assert((std::is_same<decltype(getwc(fp)), wint_t>::value), ""); static_assert((std::is_same<decltype(putwc(L' ', fp)), wint_t>::value), ""); static_assert((std::is_same<decltype(ungetwc(L' ', fp)), wint_t>::value), ""); static_assert((std::is_same<decltype(wcstod(L"", (wchar_t**)0)), double>::value), ""); static_assert((std::is_same<decltype(wcstof(L"", (wchar_t**)0)), float>::value), ""); static_assert((std::is_same<decltype(wcstold(L"", (wchar_t**)0)), long double>::value), ""); static_assert((std::is_same<decltype(wcstol(L"", (wchar_t**)0, 0)), long>::value), ""); static_assert((std::is_same<decltype(wcstoll(L"", (wchar_t**)0, 0)), long long>::value), ""); static_assert((std::is_same<decltype(wcstoul(L"", (wchar_t**)0, 0)), unsigned long>::value), ""); static_assert((std::is_same<decltype(wcstoull(L"", (wchar_t**)0, 0)), unsigned long long>::value), ""); static_assert((std::is_same<decltype(wcscpy(ws, L"")), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcsncpy(ws, L"", s)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcscat(ws, L"")), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcsncat(ws, L"", s)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcscmp(L"", L"")), int>::value), ""); static_assert((std::is_same<decltype(wcscoll(L"", L"")), int>::value), ""); static_assert((std::is_same<decltype(wcsncmp(L"", L"", s)), int>::value), ""); static_assert((std::is_same<decltype(wcsxfrm(ws, L"", s)), size_t>::value), ""); static_assert((std::is_same<decltype(wcschr((wchar_t*)0, L' ')), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcscspn(L"", L"")), size_t>::value), ""); static_assert((std::is_same<decltype(wcslen(L"")), size_t>::value), ""); static_assert((std::is_same<decltype(wcspbrk((wchar_t*)0, L"")), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcsrchr((wchar_t*)0, L' ')), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcsspn(L"", L"")), size_t>::value), ""); static_assert((std::is_same<decltype(wcsstr((wchar_t*)0, L"")), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcstok(ws, L"", (wchar_t**)0)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wmemchr((wchar_t*)0, L' ', s)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wmemcmp(L"", L"", s)), int>::value), ""); static_assert((std::is_same<decltype(wmemcpy(ws, L"", s)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wmemmove(ws, L"", s)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wmemset(ws, L' ', s)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcsftime(ws, s, L"", tm)), size_t>::value), ""); static_assert((std::is_same<decltype(btowc(0)), wint_t>::value), ""); static_assert((std::is_same<decltype(wctob(w)), int>::value), ""); static_assert((std::is_same<decltype(mbsinit(&mb)), int>::value), ""); static_assert((std::is_same<decltype(mbrlen("", s, &mb)), size_t>::value), ""); static_assert((std::is_same<decltype(mbrtowc(ws, "", s, &mb)), size_t>::value), ""); static_assert((std::is_same<decltype(wcrtomb(ns, L' ', &mb)), size_t>::value), ""); static_assert((std::is_same<decltype(mbsrtowcs(ws, (const char**)0, s, &mb)), size_t>::value), ""); static_assert((std::is_same<decltype(wcsrtombs(ns, (const wchar_t**)0, s, &mb)), size_t>::value), ""); // These tests fail on systems whose C library doesn't provide a correct overload // set for wcschr, wcspbrk, wcsrchr, wcsstr, and wmemchr, unless the compiler is // a suitably recent version of Clang. #if !defined(__APPLE__) || defined(_LIBCPP_PREFERRED_OVERLOAD) static_assert((std::is_same<decltype(wcschr((const wchar_t*)0, L' ')), const wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcspbrk((const wchar_t*)0, L"")), const wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcsrchr((const wchar_t*)0, L' ')), const wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcsstr((const wchar_t*)0, L"")), const wchar_t*>::value), ""); static_assert((std::is_same<decltype(wmemchr((const wchar_t*)0, L' ', s)), const wchar_t*>::value), ""); #endif #ifndef _LIBCPP_HAS_NO_STDIN static_assert((std::is_same<decltype(getwchar()), wint_t>::value), ""); static_assert((std::is_same<decltype(vwscanf(L"", va)), int>::value), ""); static_assert((std::is_same<decltype(wscanf(L"")), int>::value), ""); #endif #ifndef _LIBCPP_HAS_NO_STDOUT static_assert((std::is_same<decltype(putwchar(L' ')), wint_t>::value), ""); static_assert((std::is_same<decltype(vwprintf(L"", va)), int>::value), ""); static_assert((std::is_same<decltype(wprintf(L"")), int>::value), ""); #endif }