the story began when i wanted to create password program(insertion password)
my thought was that insert char by char and transforms any char into star symbol(*) of course after a short time of appearing
to understand what i talk about it this is the final format of the program which i create it is:
Code:
#include <stdio.h>
#include <stdlib.h>
#include<stdbool.h>
#include<windows.h>
#include<time.h>
#include<conio.h>
COORD coord={0,0};
void gotoxy(int x,int y);
int main(void)
{
char password[20];
int i=0,j=0;
clock_t cpu_start=0L;
while(1)
{
password[i]=getch();
if(password[i]=='\r')/// new_line
break;
cpu_start=clock();
gotoxy(j,0);
putchar(password[i]);
for(;clock()-cpu_start<CLOCKS_PER_SEC;);
gotoxy(j,0);
putchar('*');
i++;
j++;
}
password[i]='\0';
printf("\nthe password which you entered is; %s",password);
return 0;
}
///code to move the cursor in the position we want it
void gotoxy(int x,int y)
{
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
so ,before reaching this (program above )
i use this function getchar()instead of getch()
but the result was not what i want and it was that: you have to enter newline char(press enter) to any inserted char and it's impossible to do that and it's impractical,even i use getc() function.
after i did the debugging process
my conclusion was that ; getchar () function stores the character which you entered in buffer memory then from buffer memory the char transmits into the variable,but the getch() function stores the char in variable immediately,and getch() equivalent to getche(),and getchar() equivalent getc()
1-is my conclusion correct or no?.
2-problem with getch() is that you can't delete the char after you write it because it stores the key of delete as a char,is there solution?