Date getDate(TCHAR *prompt) { for(;;) { String s = inputString(_T("%s"), prompt); try { Date dato(s); return dato; } catch(Exception e) { _tprintf(_T("%s\n"), e.what()); } } }
main() { float A, B, C, D, E, F, y, x; printf("Programa que calcula una ecuacion de la forma\nAx + By = C\nDx + Ey = F\n"); printf("Por favor ingrese los datos que se van pidiendo\n"); A = dato("A"); B = dato("B"); C = dato("C"); D = dato("D"); E = dato("E"); F = dato("F"); y = obtener_y(A, B, C, D, E, F); x = obtener_x(A, B, C, y); imprimir_resultado(x, y); }
void Configuracion::cargarArchivoConfig(){ char chr1='\0'; char chr2='\0'; vector<string> v; ManejadorDeArchivo man(this->rutaConfig); // Salteo el texto hasta llegar a detectar una doble barra "//" o llegar al EOF while ( ( (chr1!='/') || (chr2!='/') ) && (man.fin()!= true) ){ man.leer(&chr1,1); man.leer(&chr2,1); } // Si no se acabó el archivo comienzo el parseo while(man.fin()!= true){ man.leer(&chr1,1); if ( (chr1 == '-') || (chr1 == '+') ){ // El '-' indica que viene un argumento, el '+' indica un valor string cad(""); if (chr1 == '-') cad += "-"; man.leer(&chr1,1); while( (chr1 != ' ') && (man.fin()!= true) ){ cad += chr1; man.leer(&chr1,1); } v.push_back(cad); } } // Acá ya tengo lleno el vector de strings, ahora lo paso al argc y argv int argc = v.size()+1; // El "+1" es para no usar la posición [0] int i; char** argv = new char*[argc]; argv[0] = new char[(this->rutaConfig).size()+1](); strcpy (argv[0], (this->rutaConfig).c_str() ); for(i=0; i<(int)v.size() ; i++ ){ string dato (v[i]); int size = dato.size(); argv[i+1] = new char[size+1](); // El "+1" es por el caracter de fin de string al hacer strcpy strcpy (argv[i+1], dato.c_str()); } // Ahora cargo los parámetros que se obtuvieron del archivo de configuración this->rutaArbol = ""; this->rutaHash = ""; this->rutaApellidos= ""; this->rutaDistritos = ""; this->rutaDomicilios = ""; this->rutaDomicilios = ""; this->rutaLog = ""; this->rutaNombres = ""; this->rutaInformes = ""; this->claveVigenere = ""; this->tamanioNodo = 0; this->tamanioBucket = 0; int index,c; opterr = 0; optind = 1; // Inicalo la variable para poder usar el getopt otra vez while ((c = getopt (argc, (char* const*)argv, "A:D:N:B:P:S:M:C:R:L:I:K:")) != -1) switch (c){ case 'D': this->rutaHash = optarg; break; case 'A': this->rutaArbol = optarg; break; case 'N': this->tamanioNodo = atoi(optarg); break; case 'B': this->tamanioBucket = atoi(optarg); break; case 'P': this->rutaPass = optarg; break; case 'S': this->rutaApellidos = optarg; break; case 'M': this->rutaNombres = optarg; break; case 'C': this->rutaDistritos = optarg; break; case 'R': this->rutaDomicilios = optarg; break; case 'L': this->rutaLog = optarg; break; case 'I': this->rutaInformes = optarg; break; case 'K': this->claveVigenere = optarg; break; case '?': if (optopt == 'A')fprintf (stderr, "Arch. Config. > La opción -%c requiere un argumento.\n",optopt); else if (optopt == 'D')fprintf (stderr, "Arch. Config. > La opción -%c requiere un argumento.\n",optopt); else if (optopt == 'N')fprintf (stderr, "Arch. Config. > La opción -%c requiere un argumento.\n",optopt); else if (optopt == 'B')fprintf (stderr, "Arch. Config. > La opción -%c requiere un argumento.\n",optopt); else if (optopt == 'P')fprintf (stderr, "Arch. Config. > La opción -%c requiere un argumento.\n",optopt); else if (optopt == 'S')fprintf (stderr, "Arch. Config. > La opción -%c requiere un argumento.\n",optopt); else if (optopt == 'M')fprintf (stderr, "Arch. Config. > La opción -%c requiere un argumento.\n",optopt); else if (optopt == 'C')fprintf (stderr, "Arch. Config. > La opción -%c requiere un argumento.\n",optopt); else if (optopt == 'R')fprintf (stderr, "Arch. Config. > La opción -%c requiere un argumento.\n",optopt); else if (optopt == 'L')fprintf (stderr, "Arch. Config. > La opción -%c requiere un argumento.\n",optopt); else if (optopt == 'I')fprintf (stderr, "Arch. Config. > La opción -%c requiere un argumento.\n",optopt); else if (optopt == 'K')fprintf (stderr, "Arch. Config. > La opción -%c requiere un argumento.\n",optopt); else if (isprint (optopt)) fprintf (stderr, "Arch. Config. > Opción desconocida `-%c'.\n", optopt); else fprintf (stderr,"Arch. Config. > Caracter de opción desconocida `\\x%x'.\n",optopt); break; default: cerr << "Arch. Config. > Corregir archivo. "<<endl; cerr << "Para ayuda consulte con: -h"<<endl; break; } for (index = optind; index < argc; index++) cerr << "Arch. Config. > Opción inválida: " << argv[index] << endl; if( (this->rutaArbol == "") || (this->rutaHash == "") ){ cerr << "Arch. Config. > Falta la ruta de archivo de Árbol y/o Hash."<<endl; cerr << "Para ayuda consulte con: -h\nPrograma terminado."<<endl; exit(1); } // Libero la memoria que yo instancié for(i=0; i<argc ; i++ ){ delete[] argv[i]; } delete[] argv; }