Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: Kenji-chan en 19 Marzo 2017, 23:59 pm



Título: duda en un bucle, programa que me ayude a gestionar un negocio
Publicado por: Kenji-chan en 19 Marzo 2017, 23:59 pm
Hola a todos, me estoy creando un programa que me ayude a gestionar un negocio y tengo una duda con la implementacion en la que he creado un bucle while que se repite unas 10000 para hacer una pequeña pausa en la ejecucion del programa mi pregunta es si esta bien hacer esto o ay otra forma de hacerlo??

este es la parte del codigo donde se implementa este codigo en la funcion void password() de la linea 77 el bucle while(!kbhit() && j < 10000) se encuentra en la linea 99

Código
  1. #include <stdio.h>
  2. #include <windows.h>
  3. #include <conio.h>
  4.  
  5. void gotoxy(int x,int y);
  6. void marcos(int x1, int y1, int x2, int y2);
  7. void texto(char* txt, int x, int y);
  8. int largoCadena(char* cadena);
  9. void titulo(char* titulo, int x, int y);
  10. void username(int x, int y, char** user);
  11. void password(int x, int y, char pass[]);
  12.  
  13. int main(){
  14.    char* user;
  15.    char pass[11];
  16.    marcos(20, 7, 60, 17);
  17.    titulo("Logger", 80, 6);
  18.    texto("Username:", 22, 12);
  19.    texto("Password:", 22, 13);
  20.    username(32, 12, &user);
  21.    password(32, 13, pass);
  22.    texto(user, 22, 19);
  23.    texto(pass, 22, 20);
  24.  
  25.    return 0;
  26. }
  27.  
  28. void gotoxy(int x,int y){
  29.    HANDLE hcon;
  30.    hcon = GetStdHandle(STD_OUTPUT_HANDLE);
  31.    COORD dwPos;
  32.    dwPos.X = x;
  33.    dwPos.Y= y;
  34.    SetConsoleCursorPosition(hcon,dwPos);
  35. }
  36.  
  37. void marcos(int x1, int y1, int x2, int y2){
  38.    int i, j;
  39.    for(i=y1; i<=y2; i++){
  40.        for(j=x1; j<=x2; j++){
  41.            gotoxy(j,i);
  42.            if(i==y1 && j==x1) printf("%c",201);
  43.            else if(i==y2 && j==x1) printf("%c",200);
  44.            else if(i==y1 && j==x2) printf("%c",187);
  45.            else if(i==y2 && j==x2) printf("%c",188);
  46.            else if(i==y1 || i==y2) printf("%c",205);
  47.            else if(j==x1 || j==x2) printf("%c",186);
  48.        }
  49.    }
  50. }
  51.  
  52. void texto(char* txt, int x, int y){
  53.    gotoxy(x,y);
  54.    printf("%s", txt);
  55. }
  56.  
  57. int largoCadena(char* cadena){
  58.    int i = 0;
  59.    while(cadena[i] != '\0')
  60.        i++;
  61.    return i;
  62. }
  63.  
  64. void titulo(char* titulo, int x, int y){
  65.    x = x/2;
  66.    x -= largoCadena(&(*titulo))/2;
  67.    gotoxy(x,y);
  68.    printf("%s", titulo);
  69. }
  70.  
  71. void username(int x, int y, char** user){
  72.    *user = malloc(sizeof(char)*20);
  73.    gotoxy(x, y);
  74.    fgets(*user, 20, stdin);
  75. }
  76.  
  77. void password(int x, int y, char pass[]){
  78.  
  79.    char tecla;
  80.    int i = 0;
  81.    gotoxy(x, y);
  82.  
  83.    do{
  84.        int j = 0;
  85.        fflush(stdin);
  86.        tecla = getch();
  87.        pass[i] = '\0';
  88.  
  89.        if(tecla == 8 && x > 32){
  90.            x--;
  91.            i--;
  92.            gotoxy(x, y);
  93.            printf(" ");
  94.            gotoxy(x, y);
  95.        }else if(tecla != 13 && tecla != 8 && i < 10){
  96.            pass[i] = tecla;
  97.            //gotoxy(x, y);
  98.            printf("%c", tecla);
  99.            while(!kbhit() && j < 10000)
  100.                j++;
  101.            gotoxy(x, y);
  102.            printf("*");
  103.            x++;
  104.            i++;
  105.        }
  106.    }while(tecla != 13);
  107. }
  108.  
  109.  



· Corregida la etiqueta de codigo para hacerla más legible (con GeSHi)
· Los titulos deben ser descriptivos
>aquí las reglas del foro (http://foro.elhacker.net/reglas.htm)
-Engel Lex