当我从用户那里获取玩家名字时,如何限制输入的大小?我这样使用:
player1 byte 36 dup(' '),0
但是当玩家输入超过36个字符时,计算机正在发出警报声并保持部分正在写入播放器2名称的一部分。
答案 0 :(得分:0)
;--------------------------------------------------------
ReadString PROC
LOCAL bufSize:DWORD, saveFlags:DWORD, junk:DWORD
;
; Reads a string from the keyboard and places the characters
; in a buffer.
; Receives: EDX offset of the input buffer
; ECX = maximum characters to input (including terminal null)
; Returns: EAX = size of the input string.
; Comments: Stops when Enter key (0Dh,0Ah) is pressed. If the user
; types more characters than (ECX-1), the excess characters
; are ignored.
; Written by Kip Irvine and Gerald Cahill
;
; Last update: 11/19/92, 03/20/2003
;--------------------------------------------------------`
所以答案是你应该将ECX设置为你能够安全地接受到缓冲区的最大字符数,包括空值。也许您没有正确设置该值 - 您可以尝试手动将其人为地缩短,例如10个字符,并验证它是否有效。