duda en un bucle, programa que me ayude a gestionar un negocio

Iniciado por Kenji-chan, 19 Marzo 2017, 23:59 PM

0 Miembros y 1 Visitante están viendo este tema.

Kenji-chan

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


#include <stdio.h>
#include <windows.h>
#include <conio.h>

void gotoxy(int x,int y);
void marcos(int x1, int y1, int x2, int y2);
void texto(char* txt, int x, int y);
int largoCadena(char* cadena);
void titulo(char* titulo, int x, int y);
void username(int x, int y, char** user);
void password(int x, int y, char pass[]);

int main(){
   char* user;
   char pass[11];
   marcos(20, 7, 60, 17);
   titulo("Logger", 80, 6);
   texto("Username:", 22, 12);
   texto("Password:", 22, 13);
   username(32, 12, &user);
   password(32, 13, pass);
   texto(user, 22, 19);
   texto(pass, 22, 20);

   return 0;
}

void gotoxy(int x,int y){
   HANDLE hcon;
   hcon = GetStdHandle(STD_OUTPUT_HANDLE);
   COORD dwPos;
   dwPos.X = x;
   dwPos.Y= y;
   SetConsoleCursorPosition(hcon,dwPos);
}

void marcos(int x1, int y1, int x2, int y2){
   int i, j;
   for(i=y1; i<=y2; i++){
       for(j=x1; j<=x2; j++){
           gotoxy(j,i);
           if(i==y1 && j==x1) printf("%c",201);
           else if(i==y2 && j==x1) printf("%c",200);
           else if(i==y1 && j==x2) printf("%c",187);
           else if(i==y2 && j==x2) printf("%c",188);
           else if(i==y1 || i==y2) printf("%c",205);
           else if(j==x1 || j==x2) printf("%c",186);
       }
   }
}

void texto(char* txt, int x, int y){
   gotoxy(x,y);
   printf("%s", txt);
}

int largoCadena(char* cadena){
   int i = 0;
   while(cadena[i] != '\0')
       i++;
   return i;
}

void titulo(char* titulo, int x, int y){
   x = x/2;
   x -= largoCadena(&(*titulo))/2;
   gotoxy(x,y);
   printf("%s", titulo);
}

void username(int x, int y, char** user){
   *user = malloc(sizeof(char)*20);
   gotoxy(x, y);
   fgets(*user, 20, stdin);
}

void password(int x, int y, char pass[]){

   char tecla;
   int i = 0;
   gotoxy(x, y);

   do{
       int j = 0;
       fflush(stdin);
       tecla = getch();
       pass[i] = '\0';

       if(tecla == 8 && x > 32){
           x--;
           i--;
           gotoxy(x, y);
           printf(" ");
           gotoxy(x, y);
       }else if(tecla != 13 && tecla != 8 && i < 10){
           pass[i] = tecla;
           //gotoxy(x, y);
           printf("%c", tecla);
           while(!kbhit() && j < 10000)
               j++;
           gotoxy(x, y);
           printf("*");
           x++;
           i++;
       }
   }while(tecla != 13);
}




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