Program to get user's details, calculate age and display all information

后端 未结 1 2016
北荒
北荒 2021-01-24 12:41

I have some code started but I am having problems saving the users string input into a variable.

Using ReadString I can get prompt the user to input a string, but after

相关标签:
1条回答
  • 2021-01-24 13:26

    Irvine's ReadString needs two arguments in EDX and ECX. It fills the memory pointed by EDX and returns in the size of the input. Since the string in [EDX] will be zero-terminated, you have to reserve space for the string and the terminating null. With AskName1 DWORD ? you reserved only 4 bytes - that's surely not enough.

    As I saw debugging, ECX should be the size of the string with null (not as mentioned: "max number of non-null chars" = size-1).

    Do it so:

    INCLUDE Irvine32.inc
    .data
        ...
        AskName1 BYTE 16 DUP (0)        ; Reserve 16 bytes and fill them with 0
        ...
    
    .code
    ...
    lea edx, AskName1                   ; EDX = address of AskName1
    mov ecx, Sizeof AskName1            ; ECX = size of AskName1
    call ReadString
    ...
    
    ; and don't forget:
    push 0
    call ExitProcess
    
    0 讨论(0)
提交回复
热议问题