❶ 在c語言中怎麼樣讓輸入的數字隱藏呢
推薦一個方法,就是一個一個字元的讀入,輸入字元立馬讀入。getchar()函數。
讀取了字元就立馬輸出一個
'\b'退格符,再輸出一個'*'覆蓋,這樣就實現了數字的隱藏。
❷ c語言,怎麼把輸入的數字像密碼一樣隱藏輸出星號啊
#include<stdio.h>
#defineMAX_STR_LEN32
charpasswd[MAX_STR_LEN]={0};
char*GetPasswd(void)
{
charc;
inti=0;
intlen=MAX_STR_LEN-1;
while((c=getch())!=' ')
{
passwd[i]=c;
putchar('*');
i++;
if(i>=len)
{
break;
}
}
returnpasswd;
}
intmain(void)
{
char*dispstr=NULL;
dispstr=GetPasswd();
printf(" thepasswordis:%s ",dispstr);
return0;
}
❸ c語言如何隱藏登陸密碼
#include<conio.h> //這個頭文件不是標准庫函數的,一般編譯器是有的,但是 unix和linux編譯器是沒有的
#define PASSWORD "123456"
int password()
{
char
p[20],i=0;
system("cls");
printf("請輸入密碼 => ");
while(p[i]=getch())
{
if(p[i]==13)
break;
if(p[i]!='\b')
{
printf("*");
i++;
}
else
{
printf("\b
\b");
i--;
}
}
p[i]='\0';
if(strcmp(p,PASSWORD)==0)
{
printf("驗證通過");
press();
return 1;
}
else
{
printf("密碼錯誤");
press();
return 0;
}
}
❹ 最新的Linux下的c語言怎麼隱藏輸入的登錄密碼,並回顯為* 不要getch()它沒用
在linux中getch可以做到不回顯,但是用法比windos中復雜一點點,以下是簡單實現,密碼設為6位,可以按退格修改,就只寫了這些功能,望採納
#include<stdio.h>
#include<curses.h>
int main()
{
int i,j=0;
char ch;
initscr();
cbreak();
noecho();
curs_set(0);
for(i=0;i<6+2*j;i++)
{
ch=getch();
addstr("*");
if(i)
{
if(ch==127)
{
j++;
move(0,i+1-2*j);
clrtoeol();
}
}
}
getch();
endwin();
return 0;
}
❺ C語言隱藏從鍵盤輸入的密碼串中第一個字元以外的所有字元
void HideCipher (char t[], char s[])
{
int i,j;
t[0]=s[0];
for (i=1; s[i]!='\0'; i++)
t[i]='*';
t[i]='\0';
}
❻ C語言 如何不回顯密碼
#include <unistd.h>
#include<stdio.h>
#include <termios.h>
char Getch()
{
char ch;
struct termios oldt, newt;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ECHO|ICANON);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
return ch;
}
void getpasswd(char *p)
{
int i=0;
printf("password:");
while((*(p+i)=Getch())!='\n')
{
putchar('*');
i++;
}
*(p+i) = '\0';
}
int main()
{
char a[10];
getpasswd(a);
printf("%s",a);
}
❼ C語言將密碼設為隱身形式該使用什麼函數
輸入的時候隱藏密碼顯示星號'*'的功能吧?
沒有直接可調用的函數,用getch(),這個函數讀取字元不顯示,然後每讀取一個字元後面跟著輸出一個『*』
#include<stdio.h>
intmain()
{
charc;
while(1)
{
c=getch();
if(c!=' ')
putchar('*');
else
break;
}
}
❽ linux系統下用C語言編了個下程序,不知道如何在輸入密碼時隱藏,只顯示「*」,求大神們幫幫忙啊 !!!
函數名: getch
功 能: 從控制台無回顯地取一個字元
用 法: int getch(void);
#include<conio.h>
#include<stdio.h>
intmain(void)
{
charp[50];
inti=-1;
do{
++i;
p[i]=getch();
putchar('*');
}while(p[i]!=13);//13為回車ascii
p[i+1]='