当我从用户那里获取玩家名字时,我如何限制输入的大小?我就是这样使用的:
player1 byte 36 dup(' '),0但当玩家输入超过36个字符时,计算机发出警报声,剩余部分写入player2名称的一部分。
发布于 2013-05-24 06:19:39
来自:http://lcs.syr.edu/faculty/pease/handouts/CSE%20281/Irvine%20Programming%20Examples/Lib32/Irvine32_Library/Irvine32.asm
;--------------------------------------------------------
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设置为您能够安全地接受到缓冲区中的最大字符数,包括null。也许您没有正确设置该值-您可以尝试手动将其缩短,例如10个字符,并验证它是否有效。
https://stackoverflow.com/questions/16722988
复制相似问题