c语言密码输入,C语言中如何实现输入密码?(在输入时显示为*号.)

  • Post author:
  • Post category:其他


该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

看下 GtkEntry 的源码不就知道了。。。

gtk_entry_get_display_text

if (end_pos <= start_pos)

return g_strdup (“”);

else if (priv->visible)

{

start = g_utf8_offset_to_pointer (text, start_pos);

end = g_utf8_offset_to_pointer (start, end_pos – start_pos);

return g_strndup (start, end – start);

}

else

{

str = g_string_sized_new (length * 2);

/* Figure out what our invisible char is and encode it */

if (!priv->invisible_char)

invisible_char = priv->invisible_char_set ? ‘ ‘ : ‘*’;

else

invisible_char = priv->invisible_char;

char_len = g_unichar_to_utf8 (invisible_char, char_str);

/*

* Add hidden characters for each character in the text

* buffer. If there is a password hint, then keep that

* character visible.

*/

password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);

for (i = start_pos; i < end_pos; ++i)

{

if (password_hint && i == password_hint->position)

{

start = g_utf8_offset_to_pointer (text, i);

g_string_append_len (str, start, g_utf8_next_char (start) – start);

}

else

{

g_string_append_len (str, char_str, char_len);

}

}

return g_string_free (str, FALSE);

}